通过Interop库C#向多个收件人发送邮件

通过Interop库C#向多个收件人发送邮件,第1张

概述我正在开发一个具有邮件发送选项的桌面应用程序.我有以下代码,它只适用于1个收件人: DialogResult status;status = MessageBox.Show("Some message", "Info", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);if (status == DialogResult.OK) 我正在开发一个具有邮件发送选项的桌面应用程序.我有以下代码,它只适用于1个收件人:

DialogResult status;status = MessageBox.Show("Some message","Info",MessageBoxbuttons.OKCancel,MessageBoxIcon.information);if (status == DialogResult.OK){    try    {        // 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 = "<HTML>" +                "<body>" +                "some HTML text" +                "</body>" +                "</HTML>";        int iposition = (int)oMsg.Body.Length + 1;        //Subject line        oMsg.Subject = txt_mailKonu.Text;        oMsg.importance = Outlook.olimportance.olimportanceHigh;        // RecipIEnt        Outlook.RecipIEnts oRecips = (Outlook.RecipIEnts)oMsg.RecipIEnts;            //Following line causes the problem          Outlook.RecipIEnt oRecip = (Outlook.RecipIEnt)oRecips.Add(senderForm.getRecipIEntList().ToString());        oRecip.Resolve();        //oRecip.Resolve();        // Send.        oMsg.Send();        // Clean up.        oRecip = null;        oRecips = null;        oMsg = null;        oApp = null;        MessageBox.Show("Successful",MessageBoxbuttons.OK,MessageBoxIcon.information);    }    catch (Exception)    {        MessageBox.Show("Failed","Eror",MessageBoxIcon.Error);    }                }

我在粗线处得到错误,我在以下模式中添加多个收件人:
[email protected]; [email protected]

它适用于1个地址,但是当我将多个地址分开时,它会抛出COM异常 – Outlook无法解析一个或多个名称.

希望你能帮助我.

解决方法@H_419_23@ 您是否尝试将多个收件人添加到oMsg.RecipIEnts?

// I assume that senderForm.getRecipIEntList() returns List<String>foreach(String recipIEnt in senderForm.getRecipIEntList()){    Outlook.RecipIEnt oRecip = (Outlook.RecipIEnt)oRecips.Add(recipIEnt);    oRecip.Resolve();}

如果需要,你可以爆炸发送者使用senderForm.getRecipIEntList().ToString()

String [] rcpts = senderForm.getRecipIEntList().ToString().Split(new string[] { "; " },StringSplitoptions.None);

并在foreach循环中使用新对象.

总结

以上是内存溢出为你收集整理的通过Interop库C#向多个收件人发送邮件全部内容,希望文章能够帮你解决通过Interop库C#向多个收件人发送邮件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1234834.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存