Posted By

pckujawa on 04/21/10


Tagged

email gmail apps


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

hinesnetwork
Priestd09
icecreamboyy


Sending emails (particularly with gmail and google apps for domains)


 / Published in: C#
 

URL: http://www.google.com/support/forum/p/Google+Apps/thread?tid=3abf482d7d7e24d3&hl=en&fid=3abf482d7d7e24d3000484c10943499b

For both gmail and gApps, use smtp.gmail.com on port 25 with SSL and NetworkCredentials.

Neither can send email to their own address, but they can send to other addresses.

NLog has an example of how to automatically send emails in order to log info from an app.

  1. string host = "smtp.gmail.com";
  2. int port;
  3. //port = 587; // with TLS
  4. //port = 465; // with SSL
  5. port = 25; // normal - works for my gmail account with enableSSL
  6. string fromEmail = "[email protected]";
  7. var fromAddress = new MailAddress(fromEmail);
  8. var toAddress = new MailAddress("[email protected]");
  9. MailMessage message = new MailMessage(fromAddress, toAddress)
  10. {
  11. Subject = "subject",
  12. Body = "body",
  13. };
  14. var smtp = new SmtpClient(host, port) {
  15. Credentials=new NetworkCredential(fromEmail, "password"),
  16. EnableSsl = true,
  17. Timeout = 30000,
  18. };
  19.  
  20. try {
  21. smtp.Send(message);
  22. }
  23. catch(SmtpException se) {
  24. //log
  25. }
  26. message.Dispose();

Report this snippet  

You need to login to post a comment.