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


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.

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";

for example this code it does not work,,

Try out this code.

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.Subject = "Rental Agreement Form";
            message.From = new System.Net.Mail.MailAddress("user@msssoftware.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;
            Label3.Text = "Mail sent Successfully";

Edited 6 Years Ago 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.