Guest User

Untitled

a guest
Dec 16th, 2017
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. SmtpClient smtpClient = new SmtpClient();
  2. Attachment att=new System.Net.Mail.Attachment("Path");
  3. smtpClient.EnableSsl = true;
  4. smtpClient.Port = 25;
  5. smtpClient.Timeout = 20000;
  6. smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
  7. smtpClient.UseDefaultCredentials = false;
  8. smtpClient.Host = "smtp.gmail.com";
  9. smtpClient.Credentials = new System.Net.NetworkCredential
  10. (from@gmail.com, "password" );
  11.  
  12.  
  13. System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress(from@gmail.com,
  14. from,
  15. System.Text.Encoding.UTF8);
  16.  
  17. System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress("to@gmail.com");
  18.  
  19.  
  20.  
  21. MailMessage message = new MailMessage(from, to);
  22. message.Body = "some text";
  23. message.BodyEncoding = System.Text.Encoding.UTF8;
  24. message.Subject = "Subject";
  25. message.SubjectEncoding = System.Text.Encoding.UTF8;
  26. message.Bcc.Add(bcc@gmail.com);
  27.  
  28.  
  29.  
  30. message.Attachments.Add(att);
  31.  
  32. try
  33. {
  34. smtpClient.Send(message);
  35. }
  36. catch (System.Net.Mail.SmtpException ex)
  37. {
  38. MessageBox.Show(ex.Message); // The operation has timed out
  39. }
Add Comment
Please, Sign In to add comment