Guest User

Untitled

a guest
Jul 15th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
  2. message.To.Add("sumitdawar@hotmail.com");
  3. message.To.Add("sumitdawar@gmail.com");
  4. message.Subject = "This is sample mail";
  5. message.From = new System.Net.Mail.MailAddress("Sumit.Dhingra@niit.com");
  6. message.Body = "this is the message body";
  7.  
  8.  
  9. System.Net.Mail.SmtpClient sss = new System.Net.Mail.SmtpClient("HO-KKJ-MAIL.in.niit.com");
  10. sss.UseDefaultCredentials = false;
  11. sss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
  12. sss.Credentials = new System.Net.NetworkCredential("Sumit.Dhingrar", "password","domain");
  13.  
  14. string from = me@gmail.com; //Replace this with your own correct Gmail Address
  15.  
  16. string to = you@gmail.com //Replace this with the Email Address to whom you want to send the mail
  17.  
  18. System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
  19. mail.To.Add(to);
  20. mail.From = new MailAddress(from, "One Ghost" , System.Text.Encoding.UTF8);
  21. mail.Subject = "This is a test mail" ;
  22. mail.SubjectEncoding = System.Text.Encoding.UTF8;
  23. mail.Body = "This is Email Body Text";
  24. mail.BodyEncoding = System.Text.Encoding.UTF8;
  25. mail.IsBodyHtml = true ;
  26. mail.Priority = MailPriority.High;
  27.  
  28. SmtpClient client = new SmtpClient();
  29. //Add the Creddentials- use your own email id and password
  30.  
  31. client.Credentials = new System.Net.NetworkCredential(from, "Password");
  32.  
  33. client.Port = 587; // Gmail works on this port
  34. client.Host = "smtp.gmail.com";
  35. client.EnableSsl = true; //Gmail works on Server Secured Layer
  36. try
  37. {
  38. client.Send(mail);
  39. }
  40. catch (Exception ex)
  41. {
  42. Exception ex2 = ex;
  43. string errorMessage = string.Empty;
  44. while (ex2 != null)
  45. {
  46. errorMessage += ex2.ToString();
  47. ex2 = ex2.InnerException;
  48. }
  49. HttpContext.Current.Response.Write(errorMessage );
  50. } // end try
  51.  
  52. message.From = new System.Net.Mail.MailAddress("Sumit.Dhingra@niit.com");
Add Comment
Please, Sign In to add comment