0

Hello,
Could you please help me in writing a code for sending an e-mail in c#...

Regards..

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by maryjessicka
1

Have you written any code yet? If not do so as we do not do work for you. We are only here to help if you have a problem. So write some code and if you have a specific question or problem post it here with your code and we will try to help you. Otherwise you will need to hire someone to do this work for you.

0

Sure I worked on it before, but because I am new for c# I faced many problems,

System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage();
message.From="from e-mail";
message.To="to e-mail";
message.Subject="Message Subject";
message.Body="Message Body";
System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(message);

for example this code it does not work,,

0

Try out this code.

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            //message.To.Add("xxxx@gmail.com");
            message.Subject = "Rental Agreement Form";
            message.From = new System.Net.Mail.MailAddress("user@msssoftware.com");
            message.To.Add("xxxx@gmail.com");
            //message.CC.Add("xxxx@gmail.com");
            message.IsBodyHtml = true;
            message.Body = result;
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 25);
            smtp.Host = "localhost";
            smtp.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            smtp.Send(message);
            Label3.Text = "Mail sent Successfully";

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.