使用 Outlook MailItem 循环发送多封电子邮件
您好,我正在开发一个 Outlook 插件,作为工作流程的一部分,它应该采用 mailItem
正文和主题,并且对于每个收件人,它应该根据收件人电子邮件更改邮件正文。
问题是它只发送第一封电子邮件,在 Send();
之后它不会将电子邮件发送给其他收件人
Outlook.Application application = Globals.ThisAddIn.Application;
Outlook.Inspector inspector = application.ActiveInspector();
Outlook.MailItem myMailItem = (Outlook.MailItem)inspector.CurrentItem;
myMailItem.Save();
if (myMailItem != null)
{
myMailItem.Save();
PorceesData(myMailItem);
}
..
..
..
..
private void ProcessData(MailItem oMailItem)
{
Recipients recipients = oMailItem.Recipients;
string Body = oMailItem.Body;
string To = oMailItem.To;
string CC = oMailItem.CC;
string bcc = oMailItem.BCC;
foreach (Recipient r in recipients)
{
if (r.Resolve() == true)
{
string msg = "Hello open the attached file (msg.html);
string address = r.Address;
oMailItem.Body = msg;
oMailItem.To = address;
oMailItem.Subject = "my subject"
foreach (Attachment t in oMailItem.Attachments)
{
t.Delete();
}
oMailItem.Attachments.Add(@"mydirectory");
oMailItem.Send();
}
Hello I am developing an outlook Add-on, as part of the work flow it should take the mailItem
body and subject, and for each recipient it should change the body of message according to recipient e-mail.
The problem is that it just sends the first e-mail and after Send();
it does not send the e-mail to other recipients
Outlook.Application application = Globals.ThisAddIn.Application;
Outlook.Inspector inspector = application.ActiveInspector();
Outlook.MailItem myMailItem = (Outlook.MailItem)inspector.CurrentItem;
myMailItem.Save();
if (myMailItem != null)
{
myMailItem.Save();
PorceesData(myMailItem);
}
..
..
..
..
private void ProcessData(MailItem oMailItem)
{
Recipients recipients = oMailItem.Recipients;
string Body = oMailItem.Body;
string To = oMailItem.To;
string CC = oMailItem.CC;
string bcc = oMailItem.BCC;
foreach (Recipient r in recipients)
{
if (r.Resolve() == true)
{
string msg = "Hello open the attached file (msg.html);
string address = r.Address;
oMailItem.Body = msg;
oMailItem.To = address;
oMailItem.Subject = "my subject"
foreach (Attachment t in oMailItem.Attachments)
{
t.Delete();
}
oMailItem.Attachments.Add(@"mydirectory");
oMailItem.Send();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_MailItem.Send()
关闭当前检查器。这不在中_MailItem.Send
文档,而是实际的 Outlook 实现。您可能应该想出另一种方法。我建议为您要发送的每条消息创建一个新的MailItem
实例。您可以使用...创建一个新的
MailItem
发送给所有收件人后,您可以使用以下命令手动关闭当前检查器(
Send()
隐式调用此方法)_MailItem.Send()
closes the current inspector. This isn't in the_MailItem.Send
documentation, but is the actual Outlook implementation. You should probably come up with another approach. I'd suggest creating a newMailItem
instance for each message you wish to send.You can create a new
MailItem
using...After sending to all recipients you can manually close the current inspector using the following (
Send()
implicitly calls this method)