Sorry, the previous blog contains a class which has been deprecated. Please use the namespace System.Net.Mail instead of System.Web.Mail;
Moreover, mails sent in previous way were being marked as spam in GMail. Use a real mail server to reduce the probability of being spam. Here Google mail server has been used along with GMail account and password.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
MailMessage mail = new MailMessage("from@mail.com", "to@mail.com", "Subject", "Body");
smtp.Credentials = new System.Net.NetworkCredential("user@gmail.com", "password");
smtp.EnableSsl = true;
smtp.Send(mail);
Note:
- ‘from’ address will not work, rather "user@gmail.com" will be the sender.
- It is not assured that mail will not be marked as spam.
0 Comments:
Post a Comment