How to send email from C# windows application

First find the System.Web.dll in your computer drive where .NET Framework installed

Then add a reference to that dll in your C# windows application.

then write following code to send email....

string smtpServer;
smtpServer= "127.0.0.1";
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.From = "From Email Address";
msg.To = "To Email Address";
msg.Body = "Body here";
System.Web.Mail.MailAttachment attachFile = new System.Web.Mail.MailAttachment("Filepath");
System.Web.Mail.SmtpMail.SmtpServer = smtpServer; System.Web.Mail.SmtpMail.Send(msg);

Comments

  1. Got this error:

    The server rejected the sender address. The server response was: 530 5.7.0 Must issue a STARTTLS command first. z4sm18664799ibg.13

    Any suggestions?

    ReplyDelete

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Popular posts from this blog

How to create Rest API(Web API) with ASP.NET Core 1.0

Creating PDF with ASP.Net MVC and RazorPDF

Solution: gulp is not recognized as internal or external command- Visual Studio