private RDOFolder GetExchangeServerSharedDefaultDraftsFolder(string senderEmailAddress, Response response) { //_logger.Debug("[RedemptionWrapper::GetExchangeServerSharedDefaultDraftsFolder] "); if (RdoSession.ExchangeConnectionMode <= 0) return null; try { // use shared mailbox to send email var userName = RdoSession.CurrentUser.Name; var serverName = RdoSession.ExchangeMailboxServerName; RdoSession.Logoff(); // logon to Exchange server RdoSession.LogonExchangeMailbox(userName, serverName); return RdoSession.GetSharedDefaultFolder(senderEmailAddress, rdoDefaultFolders.olFolderDrafts); } catch (Exception ex) { if (response.Errors == null) response.Errors = new List<string>(); response.Errors.Add(ex.Message); response.ResponseObject = ex; } return null; }
private RDOFolder GetDefaultDraftsFolder(Response response) { try { //_logger.Debug("[RedemptionWrapper::GetDefaultDraftsFolder] "); return RdoSession.GetDefaultFolder(rdoDefaultFolders.olFolderDrafts); } catch (Exception ex) { response.Errors.Add(ex.Message); response.ResponseObject = ex; } return null; }
/// <summary> /// Send the normal email for testing /// </summary> /// <param name="senderEmailAddress"></param> /// <param name="receiverEmailAddress"></param> /// <param name="subject"></param> /// <returns></returns> public Response SendEmailMessageForTesting(string senderEmailAddress, string receiverEmailAddress, string subject) { var response = new Response(); // Search and switch to sender email profile SenderEmailAccountType senderEmailAccountType; if (!SetToSenderEmailProfile(senderEmailAddress, out senderEmailAccountType)) { MessageBox.Show(string.Format("Cannot found Profiles having Sender's Email '{0}' account", senderEmailAddress)); return null; } MessageBox.Show(string.Format("Profile '{0}' contain sender email account.", ProfileName)); // create email for send based on sender email account type Mail = CreateEmail(senderEmailAddress, senderEmailAccountType, response); Mail.DeleteAfterSubmit = false; Mail.DownloadPictures = true; Mail.Subject = Subject; Mail.To = receiverEmailAddress; Mail.Recipients.ResolveAll(true, 0); Mail.Subject = subject; Mail.Body = "Test body"; Mail.Save(); Mail.Send(); MessageBox.Show("Email is sent!"); return response; }
// do not use multiple dot notation when processing messages in a loop // http://groups.yahoo.com/neo/groups/Outlook-Redemption/conversations/topics/6568 private RDOMail CreateEmail(string senderEmailAddress, SenderEmailAccountType senderEmailAccountType, Response response) { RDOMail mail = null; if (senderEmailAccountType == SenderEmailAccountType.ExchangeSharedMailBoxAccount) { // use shared mailbox to send email // create new email in draft folder from exchange server's shared mail box var draftsFolder = GetExchangeServerSharedDefaultDraftsFolder(senderEmailAddress, response); var draftsFolderItems = draftsFolder.Items; mail = draftsFolderItems.Add(Type.Missing); } else { // use local profile draft folder to send email var draftsFolder = GetDefaultDraftsFolder(response); var draftsFolderItems = draftsFolder.Items; mail = draftsFolderItems.Add(Type.Missing); mail.Account = null; if (senderEmailAccountType == SenderEmailAccountType.DelegateForEmailAccount) { // Set "Sent as on behalf for" from default email account mail.SentOnBehalfOf = FindDelegateAddressEntry(senderEmailAddress); } else if (senderEmailAccountType == SenderEmailAccountType.NonDefaultEmailAccount) { // send from other non-default email account mail.Account = RdoSession.Accounts[senderEmailAddress]; } else if (senderEmailAccountType == SenderEmailAccountType.GoogleAppsEmailAccount) { // send from Google Apps email account mail.Account = RdoSession.Accounts[GetGoogleAppEmailAccountName(senderEmailAddress)]; } } return mail; }
public bool IsExchangeSharedMailBoxAccountEmailAddress(string senderEmailAddress) { try { if (RdoSession.ExchangeConnectionMode <= 0) return false; // check if we can get exchange server shared mail box drafts folder var response = new Response(); var isSharedMailBox = GetExchangeServerSharedDefaultDraftsFolder(senderEmailAddress, response) != null; // logon back to current local profile SessionLogon(); return isSharedMailBox; } catch { // DE2235 : As Redemption may result throw exception in some unexpected cases. we decided to ignore any exception and treat the result as not found return false; } }