Guest User

Untitled

a guest
Jan 14th, 2019
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. MailMessage mailMsg = new MailMessage();
  2. SmtpClient smtpClient = new SmtpClient();
  3.  
  4. mailMsg.To.Add("receiver@email.com");
  5. mailMsg.Subject = "Application Exception";
  6.  
  7. MemoryStream MS = new MemoryStream();
  8. StreamWriter Writer = new StreamWriter(MS);
  9. Writer.Write(DateTime.Now.ToString() + "hello");
  10. Writer.Flush();
  11. Writer.Dispose();
  12.  
  13. // Create attachment
  14. ContentType ct = new ContentType(MediaTypeNames.Text.Plain);
  15. Attachment attach =new Attachment(MS, ct);
  16. attach.ContentDisposition.FileName = "Exception Log.txt";
  17.  
  18. // Add the attachment
  19. mailMsg.Attachments.Add(attach);
  20.  
  21. // Send Mail via SmtpClient
  22. mailMsg.Body = "An Exception Has Occured In Your Application- n";
  23. mailMsg.IsBodyHtml = true;
  24. mailMsg.From = new MailAddress("sender@email.com");
  25. smtpClient.Credentials = new NetworkCredential("sender@email.com", "password");
  26. smtpClient.Host = "smtp.gmail.com";
  27. smtpClient.Port = 587;
  28. smtpClient.EnableSsl = true;
  29. smtpClient.Send(mailMsg);
Add Comment
Please, Sign In to add comment