Guest User

Untitled

a guest
Apr 20th, 2018
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. MailMessage mm = new MailMessage("xyz@gmail.com", TextBoxEmail.Text.Trim());
  2. mm.Subject = "Password Recovery";
  3. mm.Body = string.Format("Hi ,<br /><br />Your password is .<br /><br />Thank You.");
  4. mm.IsBodyHtml = true;
  5. SmtpClient smtp = new SmtpClient();
  6. smtp.Host = "smtp.gmail.com";
  7. smtp.EnableSsl = true;
  8. NetworkCredential NetworkCred = new NetworkCredential();
  9. NetworkCred.UserName = "xyz@gmail.com";
  10. NetworkCred.Password = "xyz";
  11. smtp.UseDefaultCredentials = true;
  12. smtp.Credentials = NetworkCred;
  13. smtp.Port = 587;
  14. smtp.Send(mm);
  15. message = "Registration successful. Activation email has been sent.";
  16. ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
  17.  
  18. using (MailMessage mail = new MailMessage())
  19. {
  20. mail.From = new MailAddress("xyz@gmail.com");
  21. mail.Subject = "mailSubject";
  22. mail.Body = "mailBody";
  23. mail.IsBodyHtml = true;
  24.  
  25. mail.To.Add("xyz@gmail.com");
  26.  
  27.  
  28.  
  29. using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))//2nd parameter is PORT No.
  30. {
  31. smtp.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "xyz");
  32. smtp.EnableSsl = true;//set this as your Host Name properties, for gmail,its true
  33. smtp.Send(mail);//actual sending operation here
  34. }
  35. }
  36.  
  37. using System.Net;
  38. using System.Net.Mail;
  39.  
  40. var fromAddress = new MailAddress("from@gmail.com", "From Name");
  41. var toAddress = new MailAddress("to@example.com", "To Name");
  42. const string fromPassword = "fromPassword";
  43. const string subject = "Subject";
  44. const string body = "Body";
  45.  
  46. var smtp = new SmtpClient
  47. {
  48. Host = "smtp.gmail.com",
  49. Port = 587,
  50. EnableSsl = true,
  51. DeliveryMethod = SmtpDeliveryMethod.Network,
  52. UseDefaultCredentials = false,
  53. Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  54. };
  55. using (var message = new MailMessage(fromAddress, toAddress)
  56. {
  57. Subject = subject,
  58. Body = body
  59. })
  60. {
  61. smtp.Send(message);
  62. }
Add Comment
Please, Sign In to add comment