Advertisement
Guest User

Untitled

a guest
Jul 19th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. private static async void SendEmail(LogFileType logType, SendLogJob job)
  2. {
  3. #region EMAIL_CONSTANTS
  4. string From = "abc@company.com";
  5. string To = "username@domain.com";
  6. #endregion
  7.  
  8. try
  9. {
  10. MailAddress fromUsername = new MailAddress(From);
  11. MailAddress from = new MailAddress(From, "Auto Generated Mail", System.Text.Encoding.UTF8);
  12. MailAddress to = new MailAddress(To);
  13. const string fromPassword = "1234";
  14.  
  15. var smtp = new SmtpClient
  16. {
  17. Host = "mail3.gridhost.co.uk",
  18. Port = 465,
  19. EnableSsl = true,
  20. DeliveryMethod = SmtpDeliveryMethod.Network,
  21. UseDefaultCredentials = false,
  22. Credentials = new NetworkCredential(fromUsername.Address, fromPassword)
  23. };
  24.  
  25.  
  26.  
  27. var message = new MailMessage(from, to)
  28. {
  29. Subject = "Subject of the Email goes here",
  30. Body = "This is the EMail Body",
  31. IsBodyHtml=true,
  32. SubjectEncoding = System.Text.Encoding.UTF8,
  33. BodyEncoding = System.Text.Encoding.UTF8
  34. };
  35.  
  36. smtp.SendCompleted += (s, e) =>
  37. {
  38. SendCompletedCallback(s, e);
  39. smtp.Dispose();
  40. message.Dispose();
  41. };
  42. MemoryStream stream = new MemoryStream(new byte[64000]);
  43. Attachment attachment = new Attachment(stream, logType + " File");
  44. message.Attachments.Add(attachment);
  45. smtp.SendAsync(message, message);
  46.  
  47. }
  48. catch (Exception ex)
  49. {
  50. ex.Message.ToString();
  51. }
  52.  
  53. Syntax error, command unrecognized. The server response was:
  54.  
  55. at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result) at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement