Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (MailObject != null && MailObject.MailProfileId != null)
- {
- var mailProfileObject = new MailProfile().GetById(MailObject.MailProfileId ?? 0);
- if (mailProfileObject != null)
- {
- //if (mailProfileObject.Active == false) return false;
- mailman.SmtpHost = mailProfileObject.SmtpHost;
- mailman.SmtpUsername = mailProfileObject.Username;
- mailman.SmtpPassword = mailProfileObject.Password;
- mailman.SmtpSsl = mailProfileObject.EnableSsl;
- mailman.SmtpPort = mailProfileObject.Port;
- mailman.MailHost = mailProfileObject.MailHost;
- receiverPort = mailProfileObject.ReceivePort ?? 0;
- email.From = mailProfileObject.Username;
- email.FromName = mailProfileObject.DisplayName;
- email.ReplyTo = mailProfileObject.Username;
- }
- }
- success = mailman.SendEmail(email);
- if (success != true)
- {
- throw new Exception(mailman.LastErrorText);
- }
- if (mailProfileObject.SaveToSEntItems)
- {
- // Now use Chilkat IMAP to save the email to Inbox.Sent
- Chilkat.Imap imap = new Chilkat.Imap();
- // Connect to an IMAP server.
- // Use TLS
- imap.Ssl = mailman.SmtpSsl;
- if (receiverPort > 0)
- imap.Port = receiverPort;
- success = imap.Connect(mailman.MailHost);
- if (success != true)
- {
- throw new Exception(mailman.LastErrorText);
- }
- // Login
- success = imap.Login(mailman.SmtpUsername, mailman.SmtpPassword);
- if (success != true)
- {
- throw new Exception(mailman.LastErrorText);
- }
- // The AppendMail method uploads an email to an IMAP server
- // and saves it in the mailbox specified:
- success = imap.AppendMail("Sent", email); // Here we tried different folder names like 'Inbox.Sent' ,'Sent Items', 'Sent Mails','Outbox' etc.
- if (success != true) // Always failed here
- {
- throw new Exception(mailman.LastErrorText);
- }
- return success;
- }
Add Comment
Please, Sign In to add comment