Hi,
I am currently evaluating Aspose Email, currently using Outlook I use .SentOnBehalfOfName to send message from shared mailboxes.
Is there functionality to use this in aspose, I have been unable to find?
Regards
Tony
Hi Tony,
Thank you for contacting Aspose support team.
You may please use impersonation to achieve this functionality. Following is an example where one user is accessing control of other account and performing tasks.
// Create instance of EWSClient class by giving credentials
IEWSClient client1 = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "userone@ASE2015.onmicrosoft.com", "password", "");
// Create instance of EWSClient class by giving credentials
IEWSClient client2 = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "usertwo@ASE2015.onmicrosoft.com", "password", "");
{
string folder = "Drafts";
try
{
foreach (ExchangeMessageInfo messageInfo in client1.ListMessages(folder))
client1.DeleteMessage(messageInfo.UniqueUri);
string subj1 = string.Format("NETWORKNET_33354 {0} {1}", "User", "User1");
client1.AppendMessage(folder, new MailMessage("userone@ASE2015.onmicrosoft.com", "To@Aspose.com", subj1, ""));
foreach (ExchangeMessageInfo messageInfo in client2.ListMessages(folder))
client2.DeleteMessage(messageInfo.UniqueUri);
string subj2 = string.Format("NETWORKNET_33354 {0} {1}", "User", "User2");
client2.AppendMessage(folder, new MailMessage("usertwo@ASE2015.onmicrosoft.com", "To@aspose.com", subj2, ""));
ExchangeMessageInfoCollection messInfoColl = client1.ListMessages(folder);
//Assert.AreEqual(1, messInfoColl.Count);
//Assert.AreEqual(subj1, messInfoColl[0].Subject);
MailAddressCollection coll = new MailAddressCollection();
coll.Add(new MailAddress("user@aspose.com"));
client1.ImpersonateUser(ItemChoice.PrimarySmtpAddress, "usertwo@ASE2015.onmicrosoft.com");
client1.CreateAppointment(new Appointment("Location", DateTime.Now, DateTime.Now, new MailAddress("userone@ASE2015.onmicrosoft.com"), coll));
//then save page in some way and send me
ExchangeMessageInfoCollection messInfoColl1 = client1.ListMessages(folder);
//Assert.AreEqual(1, messInfoColl1.Count);
//Assert.AreEqual(subj2, messInfoColl1[0].Subject);
client1.ResetImpersonation();
ExchangeMessageInfoCollection messInfoColl2 = client1.ListMessages(folder);
//Assert.AreEqual(1, messInfoColl2.Count);
//Assert.AreEqual(subj1, messInfoColl2[0].Subject);
}
finally
{
try
{
foreach (ExchangeMessageInfo messageInfo in client1.ListMessages(folder))
client1.DeleteMessage(messageInfo.UniqueUri);
foreach (ExchangeMessageInfo messageInfo in client2.ListMessages(folder))
client2.DeleteMessage(messageInfo.UniqueUri);
}
catch { }
}
}
Similarly if you want to create an unsent email with a different from address, then give a try to the following sample code and let us know the feedback
MailMessage asposeMessage = new MailMessage();
asposeMessage.PreferredTextEncoding = Encoding.Unicode;
asposeMessage.To.Add(new MailAddress("dars@nexcom.dk", "Dars Bondergaard", false));
asposeMessage.Subject = "My test mail";
asposeMessage.Body = "TEST";
MapiMessage mapiMessage = MapiMessage.FromMailMessage(asposeMessage, OutlookMessageFormat.Unicode);
mapiMessage.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_FROMME);
mapiMessage.SetStringPropertyValue(MapiPropertyTag.PR_SENDER_ADDRTYPE, string.Empty);
mapiMessage.SetStringPropertyValue(MapiPropertyTag.PR_SENDER_EMAIL_ADDRESS, "btray@domain.dk");
mapiMessage.SetStringPropertyValue(MapiPropertyTag.PR_SENDER_NAME, "bTray");
mapiMessage.SetStringPropertyValue(MapiPropertyTag.PR_SENT_REPRESENTING_ADDRTYPE, string.Empty);
mapiMessage.SetStringPropertyValue(MapiPropertyTag.PR_SENT_REPRESENTING_EMAIL_ADDRESS, "btray@domain.dk");
mapiMessage.SetStringPropertyValue(MapiPropertyTag.PR_SENT_REPRESENTING_NAME, "bTray");