如何发送电子邮件使用System.Net.Mail多址 [英] How to send email to multiple address using System.Net.Mail

查看:486
本文介绍了如何发送电子邮件使用System.Net.Mail多址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的SMTP电子邮件功能。它适用于单一的地址,但有问题的多个地址。

我传递多个地址用code以下行。

  MailAddress为=新MailAddress(ABC @ gmail.com,某某@ gmail.com);
 

请让我知道这个问题,因为我没有得到任何错误。

解决方案

  MailMessage味精=新MailMessage();
msg.Body = ....;
msg.To.Add(...);
msg.To.Add(...);

SmtpClient SMTP =新SmtpClient();
smtp.Send(MSG);
 

MailAddressCollection ,这样你就可以添加多少地址需要。

如果你需要一个显示名称,试试这个:

  MailAddress为=新MailAddress(
    的String.Format({0}< {1}>中,DISPLAY_NAME,地址));
 

I have smtp email functionality. it works for single address but has problem in multiple address.

i am passing multiple addresses using following line of code.

MailAddress to = new MailAddress("abc@gmail.com,xyz@gmail.com");

Please let me know the problem as i am not getting any error.

解决方案

MailMessage msg = new MailMessage();
msg.Body = ....;
msg.To.Add(...);
msg.To.Add(...);

SmtpClient smtp = new SmtpClient();
smtp.Send(msg);

To is a MailAddressCollection, so you can add how many addresses you need.

If you need a display name, try this:

MailAddress to = new MailAddress(
    String.Format("{0} <{1}>",display_name, address));

这篇关于如何发送电子邮件使用System.Net.Mail多址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆