Guest User

Untitled

a guest
Jun 1st, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. if (MailObject != null && MailObject.MailProfileId != null)
  2. {
  3. var mailProfileObject = new MailProfile().GetById(MailObject.MailProfileId ?? 0);
  4. if (mailProfileObject != null)
  5. {
  6. //if (mailProfileObject.Active == false) return false;
  7. mailman.SmtpHost = mailProfileObject.SmtpHost;
  8. mailman.SmtpUsername = mailProfileObject.Username;
  9. mailman.SmtpPassword = mailProfileObject.Password;
  10. mailman.SmtpSsl = mailProfileObject.EnableSsl;
  11. mailman.SmtpPort = mailProfileObject.Port;
  12. mailman.MailHost = mailProfileObject.MailHost;
  13. receiverPort = mailProfileObject.ReceivePort ?? 0;
  14. email.From = mailProfileObject.Username;
  15. email.FromName = mailProfileObject.DisplayName;
  16. email.ReplyTo = mailProfileObject.Username;
  17. }
  18. }
  19.  
  20. success = mailman.SendEmail(email);
  21. if (success != true)
  22. {
  23. throw new Exception(mailman.LastErrorText);
  24. }
  25.  
  26. if (mailProfileObject.SaveToSEntItems)
  27. {
  28. // Now use Chilkat IMAP to save the email to Inbox.Sent
  29. Chilkat.Imap imap = new Chilkat.Imap();
  30.  
  31. // Connect to an IMAP server.
  32. // Use TLS
  33. imap.Ssl = mailman.SmtpSsl;
  34. if (receiverPort > 0)
  35. imap.Port = receiverPort;
  36. success = imap.Connect(mailman.MailHost);
  37. if (success != true)
  38. {
  39. throw new Exception(mailman.LastErrorText);
  40. }
  41.  
  42. // Login
  43.  
  44. success = imap.Login(mailman.SmtpUsername, mailman.SmtpPassword);
  45. if (success != true)
  46. {
  47. throw new Exception(mailman.LastErrorText);
  48. }
  49.  
  50. // The AppendMail method uploads an email to an IMAP server
  51. // and saves it in the mailbox specified:
  52. success = imap.AppendMail("Sent", email); // Here we tried different folder names like 'Inbox.Sent' ,'Sent Items', 'Sent Mails','Outbox' etc.
  53. if (success != true) // Always failed here
  54. {
  55. throw new Exception(mailman.LastErrorText);
  56. }
  57.  
  58. return success;
  59. }
Add Comment
Please, Sign In to add comment