Reputation:
I have a working form which sends emails from the default logged in account. I am trying to add a feature where the user can select an email account from a drop down list and send the emails via an alt address, like [email protected] or [email protected]. I am trying to use the "SendUsingAccount" option but no luck. I have look online but mostly find examples using VB which im not familiar with. My code is as follows:
Microsoft.Office.Interop.Outlook.Application objOutlook = new Microsoft.Office.Interop.Outlook.Application();
var mic = (MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));
Inspector oAddSig = null;
mic.sendusingaccount = ?????????????? //here is where i need the help
mic.Subject = "Announcing Participant Website Enhancements!";
mic.Importance = OlImportance.olImportanceHigh;
mic.BodyFormat = OlBodyFormat.olFormatHTML;
//mic.Attachments.Add(PDFAttachment + yearending.Text + ".pdf");
object emailBody = ToolBox.GetStringFromTextFile((string)EmailBody);
oAddSig = mic.GetInspector;
mic.HTMLBody = emailBody + mic.HTMLBody;
//mic.Display(true);
mic.Send();
Upvotes: 3
Views: 8612
Reputation: 5575
Outlook.Account account =
Application.Session.Accounts["Hotmail"];
mic.SendUsingAccount = account;
May be You can check the different accounts at Sessions...
You can check: MSDN
Upvotes: 1
Reputation: 43
if you have a dropdown you could create a string with the value of that dd and asign sendusingaccount = your string
Microsoft.Office.Interop.Outlook.Application objOutlook = new Microsoft.Office.Interop.Outlook.Application();
string email = yourdropdown.selectedvalue;
var mic = (MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));
Inspector oAddSig = null;
mic.sendusingaccount = email
I hope this help you
Upvotes: 2
Reputation: 15685
Well I always use the SMTP client from the System.Net.Mail namespace. It has a method called 'send' that allows you to provide the address of whom the message is 'from'
Check it out: http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
As long as you know the address of your exchange server (which should be OK since you are trying to use outlook in your example) everything should be A-OK. Probably a bit easier than the approach above too.
Upvotes: 3