Sending Email from C#

Pure code is here. You can just copy and use it, and you can understand easily from the comments.

string to = ""; // here the username can be any address // this is the address that the reciever will reply to when he/she hits the Reply button // this doesn't have to be the same as the credential address below. string from = ""; string subject = "My mail from C#"; string body = "<a href=\"\"> Click here </a><br/><img src=\"\"/>"; System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(from, to, subject, body); msg.IsBodyHtml = true; // adding attachement System.Net.Mail.Attachment at = new System.Net.Mail.Attachment(@"C:\Users\Thurupathan\Desktop\"); msg.Attachments.Add(at); // sending from the gmail account // for the hotmail / live / outlook => port => 587 System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("", 587); // provide credentials System.Net.NetworkCredential gmailAuthentication = new System.Net.NetworkCredential("", "password"); smtp.Credentials = gmailAuthentication; // SSL enable based on the smtp.EnableSsl = true; try { smtp.Send(msg); } catch (Exception ex) { Console.WriteLine(ex.Message); }


Comments are closed.

Powered by

Up ↑

%d bloggers like this: