发送带有BCC列表不工作电子邮件 [英] Sending Emails with BCC list not working
问题描述
我试图发送电子邮件到一个单一到收件人,和密件抄送收件人列表。
密件的收件人列表是字符串的列表,它们被成功地被添加到MAILMESSAGE的密件集合,但实际上不被发送。如果我添加同一列表的邮件的抄送收集它工作正常。只是没有密件抄送集合。
在code我使用的是这样的:
I am trying to send emails to a single 'To' recipient, and a list of 'Bcc' recipients. The list of Bcc recipients is a list of string, and they are successfully being added to the mailMessage's Bcc collection, but not actually being sent. If I add the same list to the message's 'Cc' collection it works fine. Just not the Bcc collection. The code I'm using is this:
public void SendEmailMessage(String FromAddress, String ToAddress, String Subject, String Body, List<String> CCAddress, List<String> BccAddress, String Filepath)
{
using (SmtpClient mailClient = new SmtpClient())
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(FromAddress);
mailMessage.To.Add(new MailAddress(ToAddress));
foreach (String _email in CCAddress)
{
mailMessage.CC.Add(new MailAddress(_email));
}
foreach (String _email in BccAddress)
{
mailMessage.Bcc.Add(new MailAddress(_email));
}
mailMessage.Priority = MailPriority.Normal;
mailMessage.Subject = Subject;
if (Filepath != string.Empty)
{
Attachment _attachment = new Attachment(Filepath, MediaTypeNames.Application.Octet);
mailMessage.Attachments.Add(_attachment);
}
AlternateView plainTextView = AlternateView.CreateAlternateViewFromString(GetTextonly(Body), null, "text/plain");
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
mailMessage.AlternateViews.Add(plainTextView);
mailMessage.AlternateViews.Add(htmlView);
SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
smtpClient.Send(mailMessage);
}
}
什么想法?
推荐答案
有一件事我没有提到的是,邮件放在皮卡目录,而不是直接发送。
我发现了一个博客这也说明,如果使用的是皮卡目录BCC地址不发,你可以把他们在重试目录,而不是。这解决了我的问题,一个简单的办法:
<一href=\"http://blogs.msdn.com/b/akashb/archive/2012/07/20/unable-to-send-bcc-using-system-net-mail-when-specifying-a-pickup-directory-exchange-2007-exchange-2010-in-$c$c.aspx\"相对=nofollow>无法指定分拣目录在使用System.Net.Mail密件抄送发送(交易所2007 / Exchange 2010中)在code
one thing i didn't mention is that the mail is put in a pickup directory rather than sent direct. I found a blog which explains that bcc addresses aren't sent if using a pickup directory, and you can put them in the retry directory instead. This solved my problem with an easy fix: Unable to send Bcc using System.Net.Mail when specifying a Pickup Directory(Exchange 2007/Exchange 2010) in code
这篇关于发送带有BCC列表不工作电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!