Guest User

Untitled

a guest
Dec 12th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public static bool SendEmail(string password, string from, string to, string cc, string subject, string[] attachedFiles, string body, string host, int port)
  2. {
  3. try
  4. {
  5. MailMessage mail = new MailMessage(from, to);
  6.  
  7.  
  8. //foreach (var attachedFile in attachedFiles)
  9. //{
  10. // mail.Attachments.Add(new Attachment(attachedFile.ToString()));
  11. //}
  12.  
  13.  
  14. mail.Attachments.Add(new Attachment(@"C:UsersliakaDesktopJordanFileMailerFileMailerBacklog_07_12_2018.xlsx"));
  15. mail.Attachments.Add(new Attachment(@"C:UsersliakaDesktopJordanFileMailerFileMailertest.txt"));
  16.  
  17. mail.Subject = subject;
  18. mail.Body = body;
  19. mail.CC.Add(cc);
  20.  
  21. var client = new SmtpClient(host, port)
  22. {
  23. Credentials = new NetworkCredential(from, password),
  24. EnableSsl = true
  25. };
  26. client.Send(mail);
  27. return true;
  28. }
  29. catch (Exception ex)
  30. {
  31. return false;
  32. }
  33.  
  34. }
Add Comment
Please, Sign In to add comment