我尝试使用控制台应用程序中的Outlook以编程方式发送电子邮件。
这是我的代码:
Outlook.Application app = new Outlook.Application();
Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);
Microsoft.Office.Interop.Outlook.NameSpace oNamespace = app.GetNamespace("MAPI");
Outlook.MAPIFolder folder = oNamespace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
mailItem.Subject = "Mail sent " + DateTime.Today.ToShortDateString();
mailItem.To = "email@example.com";//I'm using a real e-mail here
//this is copied from the msdn, it scans the available Account object
//in outlook and return the one with the specified email address
Outlook.Account account = GetAccountForEmailAddress(app, "myemail@example.com");
mailItem.SendUsingAccount = account;
string message = "test mail";
mailItem.HTMLBody = message;
mailItem.Display(true);
//again copied from the msdn, casts the send method to avoid errors
((Microsoft.Office.Interop.Outlook._MailItem)mailItem).Send();
电子邮件已发送但未收到,我在发送帐户上收到了一封报告邮件(已翻译!)消息
Can't reach the following address(es)
'email@example.com' 03/08/2014 17:48
server error: "530 Authentication required"
我想使用Outlook.Application
而不是SmtpClient
,因为这个程序必须使用他们的凭据从许多计算机上运行,在我看来,这是使用Outlook帐户的最佳方式。