I've got a method that basically has开发者_如何学Python a "SendEmail" method (it will later be used by WCF service)
It has params like, Subject, Body, etc... and a string[] of Recipients. What I do, is create a MailMessage based on the parameters, then send it using smtp - I know the MailMessage has a To MailAddressCollection, but if I add each address to that, the message is CC'd to each and every person in the collection.
What I want to do is send it to them seperateley.
Is there any way of doing this, other than creating a seperate mail message for each item in the Recipient array, and sending it that way? I don't want to just BCC it to them either... as far as i know that's still recorded in the headers of the mail, and it's not particularly elegant.
I think in this particular scenario you are restricted to creating a separate MailMessage object.
may be you can use something like this:
MailMessage msg= new MailMessage();
msg.Subject = *your subject text*;
msg.From = new MailAddress(*your address*, *your title*;);
msg.Body = *your body text*;;
foreach (DataRow row in dsRecipients .Tables[0].Rows)
{
foreach (DataColumn col in dsRecipients .Tables[0].Columns)
{
msg.To.Clear();
msg.To.Add(new MailAddress((string)row[col]));
server.Send(msg);
}
}
where dsRecipients is a Dataset populated with your recipients.
精彩评论