我想通过我的代码发送电子邮件,我使用具有Windows身份验证的Intranet使用Outlook 2016。
我的代码是
public void sendmail ()
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody = "Test email for body!!";
//Add an attachment.
String sDisplayName = "MyAttachment";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
//now attached the file
Outlook.Attachment oAttach = oMsg.Attachments.Add
(@"P:\\DA.PDF", iAttachType, iPosition, sDisplayName);
//Subject line
oMsg.Subject = "Test Mail";
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("mo.ja@gmail.com");
oRecip.Resolve();
// Send.
oMsg.Send();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
}
catch (Exception ex)
{
}
但我收到此消息:
消息的翻译:程序试图访问存储在Outlook中的电子邮件地址信息。如果此操作是意外操作,请单击拒绝,并确认您的防病毒软件是最新的
当我单击接受者按钮时,电子邮件会顺利通过
任何想法!!!谢谢