我一直在尝试弄清楚如何通过 C# 向多个收件人发送 Outlook 电子邮件。现在我可以在收件人之间进行循环,但是我的发件箱中将会有很多已发送的电子邮件。
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
oMsg.HTMLBody ="test";
oMsg.Subject = "test" ;
Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)oMsg.Recipients;
Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add("xxx@xxx.com");
oRecip.Resolve();
oMsg.Send();
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
Run Code Online (Sandbox Code Playgroud)
如果我向其中添加多个地址,例如: (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add("xxx@xxx.com,yyy@yyy.com,zzz@zzz.com") 这将无法正常工作。谁可以帮我这个事?
您只需用分号分隔每个用户。例如,看看我下面的代码。
Outlook.MailItem mail = null;
Outlook.Application objApp = new Outlook.Application();
mail=(Outlook.MailItem)objApp.CreateItem(Outlook.OlItemType.olMailItem);
mail.Subject ="HI";
mail.To = "personone@yahoo.com; Persontwo@yahoo.com";
mail.Attachments.Add("C:\SOME_FOLDER\SomeFile");
mail.Body="xxxxxx";
mail.Send();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14584 次 |
| 最近记录: |