-2

我想为单击电子邮件表单提交按钮时要发送/转发的消息添加一个额外的电子邮件地址,最简单的方法是什么?

public partial class Contact : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
    string name = txtName.Text;
    string emailaddress = txtEmail.Text;
    string body = txtComment.Text;


    MailAddress From = new MailAddress(emailaddress);
    MailAddress To = new MailAddress("111@1111.com");
    MailMessage email = new MailMessage(From, To);
    email.Subject = "Comment from Website from " + name;
    email.Body = body;

    SmtpClient smtp = new SmtpClient("smtp.1111.com");
    smtp.Credentials = new System.Net.NetworkCredential("111@1111.com", "1111111111");
    smtp.Send(email);
    email.Dispose();

    ClientScript.RegisterClientScriptBlock(this.GetType(), "Email Confirm", "alert('Email Sent!');", true);

    txtComment.Text = "";
    txtEmail.Text = "";
    txtName.Text = "";


}
protected void txtEmail_TextChanged(object sender, EventArgs e)
{

}
}

我们会说我的额外电子邮件地址是 smtp.2222.com 222@2222.com,身份验证为 22222。感谢大家的关注。

4

2 回答 2

4

简单的:

…
MailAddress From = new MailAddress(emailaddress);
MailMessage email = new MailMessage(from, to);
email.To.Add(new MailAddress("111@1111.com"));
email.To.Add(new MailAddress("222@2222.com"));
email.Subject = "Comment from Website from " + name;
email.Body = body;
…
于 2013-03-18T23:12:39.470 回答
-1

To.Add您可以将逗号分隔的电子邮件地址列表传递给构造函数,而不是使用该方法,MailMessage这是一个更好的解决方案,特别是如果您有多个电子邮件地址可以将电子邮件发送到...

var from = "me@me.com";
var to = "mail1@domain.com,mail2@domain.com,mail3@domain.com";
var subject = "My Subject";
var body = "Message Body";
var message = new MailMessage(from, to, subject, body);

也能正常工作...

于 2013-03-18T23:37:16.497 回答