如何在asp.net中向多人发送gmail [英] How to send gmail to multiple person in asp.net

查看:61
本文介绍了如何在asp.net中向多人发送gmail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,,,

我的问题是如何将gmail发送给asp.net中的多人。我已经通过asp.net代码向一个人发送电子邮件。但现在我想发送给一对多人发电子邮件。

喜欢...



来自=me@gmail.com

to = you1 @ gmail.com,you2 @ gmail.com




发送电子邮件一对一代码




使用System.Net.Mail;



protected void btnSend_Click(object sender,EventArgs e)< br $>
{



string from =megmail@gmail.com;

string to =you @ gmail .com;



System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

mail。 To.Add(to);

mail.From = new MailAddress(from,One Ghost,System.Text.Encoding.UTF8);

mail.Subject = txtsubject.Text;

mail.SubjectEncoding = System.Text.Encoding.UTF8;

mail.Body = txtMsg.Text;

mail.BodyEncoding = System.Text.Encoding.UTF8;

mail.IsBodyHtml = true;

mail.Priority = MailPriority.High;



SmtpClient客户端=新的SmtpClient();



client.Credentials = new System.Net.NetworkCredential(from,Password);



client.Port = 587;

client.Host =smtp.gmail.com;

client.EnableSsl = true;

试试

{



client.Send(mail);

}

catch(exception ex)

{

异常ex2 = ex;

string errorMessage = string.Empty;

while(ex2!= null)

{

errorMessage + = ex2.To String();

ex2 = ex2.InnerException;

}

HttpContext.Current.Response.Write(errorMessage);

//txtMsg.Text = ex.Message;

//mail.Subject = ex.Message;

//mail.Body = txtMsg.Text;

}

}

Hello,,,
My Question is How to send gmail to multiple person in asp.net.I have send email one to one person through asp.net code.But now i want to send email one to many person.
Like...

from=me@gmail.com
to=you1@gmail.com,you2@gmail.com


Code of send email one to one person


using System.Net.Mail;

protected void btnSend_Click(object sender, EventArgs e)
{

string from = "megmail@gmail.com";
string to = "you@gmail.com";

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "One Ghost", System.Text.Encoding.UTF8);
mail.Subject = txtsubject.Text;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = txtMsg.Text;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;

SmtpClient client = new SmtpClient();

client.Credentials = new System.Net.NetworkCredential(from, Password);

client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{

client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
HttpContext.Current.Response.Write(errorMessage);
//txtMsg.Text = ex.Message;
//mail.Subject = ex.Message;
//mail.Body = txtMsg.Text;
}
}

推荐答案

只需拨打
mail.To.Add(to);

为您需要的每个电子邮件地址。

for each email address you need.


只需使用以下代码



Just use the below code

string ToMail="you1@gmail.com,you2@gmail.com,you3@gmail.com";




System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(ToMail);



要添加到System.Net.Mail.MailAddressCollection的电子邮件地址。

多个电子邮件地址必须用逗号分隔(,)。



问候,

Manoj


The e-mail addresses to add to the System.Net.Mail.MailAddressCollection.
Multiple e-mail addresses must be separated with a comma character (",").

Regards,
Manoj


要指定多个地址,您需要使用 属性 MailAddressCollection

To specify multiple addresses you need to use the To property which is a MailAddressCollection
message.To.Add("You1@test.com, You2@test.com"));


这篇关于如何在asp.net中向多人发送gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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