使用Outlook帐户C#中未列出的帐户从Outlook发送邮件

时间:2018-04-17 11:25:01

标签: c# outlook

我想,我想不可能,但我会问,以防万一。我在VS 2010和Outlook 2003上使用.NET Framework 4.

我想通过outlook发送电子邮件。但是我想在更高版本中指定来自newMail.SendUsingAccount命令的发送,并且此帐户发送不在Outlook帐户中。这可能吗?

我有这段代码

Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem) oApp.CreateItem(Outlook.OlItemType.olMailItem); // Create a new mail item.

oMsg.HTMLBody = "Hello, NXYLO your message body will go here!!"; // Set HTMLBody. 

String sDisplayName = "MyAttachment";
int iPosition = (int) oMsg.Body.Length + 1;
int iAttachType = (int) Outlook.OlAttachmentType.olByValue;
Outlook.Attachment oAttach = oMsg.Attachments.Add(TBattachment.Text, iAttachType, iPosition, sDisplayName); //Add an attachment.

oMsg.Subject = "Your Subject will go here."; //Subject line
oMsg.Importance = Outlook.OlImportance.olImportanceNormal;

Outlook.Recipients oRecips = (Outlook.Recipients) oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient) oRecips.Add(TBrecipient.Text); // Add a recipient.
oRecip.Resolve();
// Send.
oMsg.SaveAs(@"C:\Nxylo\mail.msg");
((Outlook._MailItem) oMsg).Send(); // oMsg.Send() Ambiguity between method 'Microsoft.Office.Interop.Outlook._MailItem.Send()' and non-method 'Microsoft.Office.Interop.Outlook.ItemEvents_10_Event.Send'. Using method group.
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;

0 个答案:

没有答案