Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
  2. smtpClient.Port = 587;
  3. ... etc
  4.  
  5. <system.net>
  6. <mailSettings>
  7. <smtp from="example@gmail.com" deliveryMethod="Network" >
  8. <network host="smtp.gmail.com" defaultCredentials="true"
  9. port="587" enableSsl="true" userName="example@gmail.com"
  10. password="example"/>
  11. </smtp>
  12. </mailSettings>
  13. </system.net>
  14.  
  15. [HttpPost]
  16. public ActionResult SubmitFeature(FormData formData)
  17. {
  18. SmtpClient smtpClient = new SmtpClient();
  19.  
  20. MailMessage mail = new MailMessage();
  21. mail.To.Add(new MailAddress("example@gmail.com"));
  22. mail.Body = "Test";
  23.  
  24. smtpClient.Send(mail);
  25.  
  26. return View("Example");
  27. }
  28.  
  29. <configuration>
  30. <system.net>
  31. <mailSettings>
  32. <smtp from="myEmail@gmail.com">
  33. <network host="smtp.gmail.com"
  34. port="587"
  35. enableSsl="true"
  36. userName="myEmail@gmail.com"
  37. password="SuperSecretPwd"
  38. defaultCredentials="false" /> <!--This must be false on Gmail-->
  39. </smtp>
  40. </mailSettings>
  41. </system.net>
  42. </configuration>
  43.  
  44. var smtpClient = new SmtpClient();
  45. var msg = new MailMessage();
  46. msg.To.Add("MyOtherAddress@yahoo.com");
  47. msg.Subject = "Test";
  48. msg.Body = "This is just a test email";
  49. smtpClient.Send(msg);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement