protected void Button1_Click(object sender, EventArgs e)
{
{
MailMessage mailMessage = new MailMessage();
string strBody = WebEditor2.Text.ToString();//内容
mailMessage.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
mailMessage.IsBodyHtml = true;
mailMessage.From = new MailAddress("\"aabb\"<advertising@aabb.com>");
//string sjr = sjrTextBox.Text.ToString();//收件人
string bt = btTextBox.Text.ToString();
Membership user = Membership.GetAllUsers();//这里不懂怎么继续写,取出EMAIL??
string aabb;
foreach( string sjr in Allusermail)//取得EMAIL后是否是这样的循环发送?
{
mailMessage.To.Add(sjr);//收件人
mailMessage.Subject = bt + "_AD";//标题
mailMessage.Body = strBody;//内容
aabb += sjr + " ";
Response.Write(aabb);//做测试用,顺充输出数据库中的邮件,实际使用时注释此行。
sendMail(mailMessage);//发送邮件
}
}
}
8 个解决方案
#1
顶起来,急啊。
#2
改成下面这样应该可以了
private void SendMyMail()
{
string SendTos = "etw_sunj@163.com"; //收件人
//获取用户的Email
SqlHelper db=new SqlHelper();
string CcTos ="";
SqlDataReader dr=db.Getdr("查询语句");
while(dr.read())
{
CcTos=CcTos+","+dr.GetString(0);
}
//string second = ",etw_sun@126.com";
string[] Receiver = System.Text.RegularExpressions.Regex.Split(SendTos + CcTos, ","); //总收件人
//string[] Receiver = System.Text.RegularExpressions.Regex.Split(SendTos + CcTos + second , ","); //总收件人
string FromMail = "liyou502@163.com"; //发件人
string Title = "你好"; //邮件主题
string Body = "附件里重要文档,请查收!"; //邮件主体
if (SendTos != "")
{
string MailUserName = "liyou502"; //FromMail.Substring(0, FromMail.IndexOf( '@ '));
string MailPassword = "****"; //发件人邮箱密码
MailMessage mailmessage = new MailMessage();
MailAddress n = new MailAddress(FromMail);
mailmessage.From = n;
mailmessage.Subject = Title;
mailmessage.Body = Body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.Credentials = new System.Net.NetworkCredential(MailUserName,MailPassword);
//向收件人和抄送人循环发送
for (int j = 0; j < Receiver.Length; j++)
{
mailmessage.To.Add(Receiver[j].ToString());
try
{
client.Send(mailmessage);
Response.Write("成功发送!");
}
catch (Exception)
{
Response.Write(" <script language= 'javascript ' >alert( '邮件发送失败! ') </script >");
}
}
}
}
private void SendMyMail()
{
string SendTos = "etw_sunj@163.com"; //收件人
//获取用户的Email
SqlHelper db=new SqlHelper();
string CcTos ="";
SqlDataReader dr=db.Getdr("查询语句");
while(dr.read())
{
CcTos=CcTos+","+dr.GetString(0);
}
//string second = ",etw_sun@126.com";
string[] Receiver = System.Text.RegularExpressions.Regex.Split(SendTos + CcTos, ","); //总收件人
//string[] Receiver = System.Text.RegularExpressions.Regex.Split(SendTos + CcTos + second , ","); //总收件人
string FromMail = "liyou502@163.com"; //发件人
string Title = "你好"; //邮件主题
string Body = "附件里重要文档,请查收!"; //邮件主体
if (SendTos != "")
{
string MailUserName = "liyou502"; //FromMail.Substring(0, FromMail.IndexOf( '@ '));
string MailPassword = "****"; //发件人邮箱密码
MailMessage mailmessage = new MailMessage();
MailAddress n = new MailAddress(FromMail);
mailmessage.From = n;
mailmessage.Subject = Title;
mailmessage.Body = Body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.Credentials = new System.Net.NetworkCredential(MailUserName,MailPassword);
//向收件人和抄送人循环发送
for (int j = 0; j < Receiver.Length; j++)
{
mailmessage.To.Add(Receiver[j].ToString());
try
{
client.Send(mailmessage);
Response.Write("成功发送!");
}
catch (Exception)
{
Response.Write(" <script language= 'javascript ' >alert( '邮件发送失败! ') </script >");
}
}
}
}
#3
那用我的方法该怎么写啊?
#4
致:cantonstar(活到老,学到老)
for (int j = 0; j < Receiver.Length; j++)
{
mailmessage.To.Add(Receiver[j].ToString());
try
{
client.Send(mailmessage);
Response.Write("成功发送!");
}
这里会导致发送的邮件为(5+4+3+2+1(假如有5个地址)
下面的是改过的
不过还是有问题啊!
详见:http://topic.csdn.net/u/20071011/16/c5bbc8a6-321c-4027-aeb6-753775e19757.html
DataSet ds = new DataSet();
public int resultCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
OleDbCommand cmd = new OleDbCommand("select count(*) from email", cn);
cn.Open();
resultCount = Convert.ToInt32(cmd.ExecuteScalar());
cn.Close();
OleDbDataAdapter dr = new OleDbDataAdapter("select email from email", cn);
cn.Open();
dr.Fill(ds);
cn.Close();
}
//群发邮件
private void SendMyMail()
{
string FromMail = "liyou502@163.com"; //发件人
string Title = txtName.Text; // 邮件主题
string Body = txtMessage.Text; //邮件主体
string MailUserName = "liyou502"; //FromMail.Substring(0, FromMail.IndexOf( '@ '));
string MailPassword = "****"; //发件人邮箱密码
MailMessage mailmessage = new MailMessage();
MailAddress n = new MailAddress(FromMail);
mailmessage.From = n;
mailmessage.Subject = Title;
mailmessage.Body = Body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.Credentials = new System.Net.NetworkCredential(MailUserName, MailPassword);
try
{
string[] Receiver = new string[resultCount];//resultCount为数据库中的行数(无空值)
for (int i = 0; i < resultCount; i++)
{
Receiver[i] = ds.Tables[0].Rows[i]["email"].ToString();
}
for (int i = 0; i < resultCount; i++)
{
if (Receiver[i] == "")
{
Receiver[i] = "service_customer@163.com";
}
MailAddress to = new MailAddress(Receiver[i].ToString());
mailmessage.To.Add(to);
client.Send(mailmessage);
mailmessage.To.Clear();
Response.Write("成功发送!");
}
}
catch (Exception)
{
Response.Write(" <script language= 'javascript ' >alert( '邮件发送失败! ') </script >");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SendMyMail();
//Response.Write(" <script >alert ( 'Email envoyé avec succès ! ');location.href= 'index.aspx '; </script >");
}
}
for (int j = 0; j < Receiver.Length; j++)
{
mailmessage.To.Add(Receiver[j].ToString());
try
{
client.Send(mailmessage);
Response.Write("成功发送!");
}
这里会导致发送的邮件为(5+4+3+2+1(假如有5个地址)
下面的是改过的
不过还是有问题啊!
详见:http://topic.csdn.net/u/20071011/16/c5bbc8a6-321c-4027-aeb6-753775e19757.html
DataSet ds = new DataSet();
public int resultCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
OleDbCommand cmd = new OleDbCommand("select count(*) from email", cn);
cn.Open();
resultCount = Convert.ToInt32(cmd.ExecuteScalar());
cn.Close();
OleDbDataAdapter dr = new OleDbDataAdapter("select email from email", cn);
cn.Open();
dr.Fill(ds);
cn.Close();
}
//群发邮件
private void SendMyMail()
{
string FromMail = "liyou502@163.com"; //发件人
string Title = txtName.Text; // 邮件主题
string Body = txtMessage.Text; //邮件主体
string MailUserName = "liyou502"; //FromMail.Substring(0, FromMail.IndexOf( '@ '));
string MailPassword = "****"; //发件人邮箱密码
MailMessage mailmessage = new MailMessage();
MailAddress n = new MailAddress(FromMail);
mailmessage.From = n;
mailmessage.Subject = Title;
mailmessage.Body = Body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.Credentials = new System.Net.NetworkCredential(MailUserName, MailPassword);
try
{
string[] Receiver = new string[resultCount];//resultCount为数据库中的行数(无空值)
for (int i = 0; i < resultCount; i++)
{
Receiver[i] = ds.Tables[0].Rows[i]["email"].ToString();
}
for (int i = 0; i < resultCount; i++)
{
if (Receiver[i] == "")
{
Receiver[i] = "service_customer@163.com";
}
MailAddress to = new MailAddress(Receiver[i].ToString());
mailmessage.To.Add(to);
client.Send(mailmessage);
mailmessage.To.Clear();
Response.Write("成功发送!");
}
}
catch (Exception)
{
Response.Write(" <script language= 'javascript ' >alert( '邮件发送失败! ') </script >");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SendMyMail();
//Response.Write(" <script >alert ( 'Email envoyé avec succès ! ');location.href= 'index.aspx '; </script >");
}
}
#5
自己再顶
#6
学习。。。
#7
把要发送的东西(写成页面形式,内容用个字段替换用)存好,然后把发送的方法单独写在一个类里
然后替换循环发送就好了
然后替换循环发送就好了
#8
好象问了两个一样的问题
答案自然也应该一样
Membership user = Membership.GetAllUsers();//这里不懂怎么继续写,取出EMAIL??
======这句不懂什么意思
取出所有用户的email address直接查询数据库不就得了
将所有用户加上后send一下既可
答案自然也应该一样
Membership user = Membership.GetAllUsers();//这里不懂怎么继续写,取出EMAIL??
======这句不懂什么意思
取出所有用户的email address直接查询数据库不就得了
将所有用户加上后send一下既可
#1
顶起来,急啊。
#2
改成下面这样应该可以了
private void SendMyMail()
{
string SendTos = "etw_sunj@163.com"; //收件人
//获取用户的Email
SqlHelper db=new SqlHelper();
string CcTos ="";
SqlDataReader dr=db.Getdr("查询语句");
while(dr.read())
{
CcTos=CcTos+","+dr.GetString(0);
}
//string second = ",etw_sun@126.com";
string[] Receiver = System.Text.RegularExpressions.Regex.Split(SendTos + CcTos, ","); //总收件人
//string[] Receiver = System.Text.RegularExpressions.Regex.Split(SendTos + CcTos + second , ","); //总收件人
string FromMail = "liyou502@163.com"; //发件人
string Title = "你好"; //邮件主题
string Body = "附件里重要文档,请查收!"; //邮件主体
if (SendTos != "")
{
string MailUserName = "liyou502"; //FromMail.Substring(0, FromMail.IndexOf( '@ '));
string MailPassword = "****"; //发件人邮箱密码
MailMessage mailmessage = new MailMessage();
MailAddress n = new MailAddress(FromMail);
mailmessage.From = n;
mailmessage.Subject = Title;
mailmessage.Body = Body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.Credentials = new System.Net.NetworkCredential(MailUserName,MailPassword);
//向收件人和抄送人循环发送
for (int j = 0; j < Receiver.Length; j++)
{
mailmessage.To.Add(Receiver[j].ToString());
try
{
client.Send(mailmessage);
Response.Write("成功发送!");
}
catch (Exception)
{
Response.Write(" <script language= 'javascript ' >alert( '邮件发送失败! ') </script >");
}
}
}
}
private void SendMyMail()
{
string SendTos = "etw_sunj@163.com"; //收件人
//获取用户的Email
SqlHelper db=new SqlHelper();
string CcTos ="";
SqlDataReader dr=db.Getdr("查询语句");
while(dr.read())
{
CcTos=CcTos+","+dr.GetString(0);
}
//string second = ",etw_sun@126.com";
string[] Receiver = System.Text.RegularExpressions.Regex.Split(SendTos + CcTos, ","); //总收件人
//string[] Receiver = System.Text.RegularExpressions.Regex.Split(SendTos + CcTos + second , ","); //总收件人
string FromMail = "liyou502@163.com"; //发件人
string Title = "你好"; //邮件主题
string Body = "附件里重要文档,请查收!"; //邮件主体
if (SendTos != "")
{
string MailUserName = "liyou502"; //FromMail.Substring(0, FromMail.IndexOf( '@ '));
string MailPassword = "****"; //发件人邮箱密码
MailMessage mailmessage = new MailMessage();
MailAddress n = new MailAddress(FromMail);
mailmessage.From = n;
mailmessage.Subject = Title;
mailmessage.Body = Body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.Credentials = new System.Net.NetworkCredential(MailUserName,MailPassword);
//向收件人和抄送人循环发送
for (int j = 0; j < Receiver.Length; j++)
{
mailmessage.To.Add(Receiver[j].ToString());
try
{
client.Send(mailmessage);
Response.Write("成功发送!");
}
catch (Exception)
{
Response.Write(" <script language= 'javascript ' >alert( '邮件发送失败! ') </script >");
}
}
}
}
#3
那用我的方法该怎么写啊?
#4
致:cantonstar(活到老,学到老)
for (int j = 0; j < Receiver.Length; j++)
{
mailmessage.To.Add(Receiver[j].ToString());
try
{
client.Send(mailmessage);
Response.Write("成功发送!");
}
这里会导致发送的邮件为(5+4+3+2+1(假如有5个地址)
下面的是改过的
不过还是有问题啊!
详见:http://topic.csdn.net/u/20071011/16/c5bbc8a6-321c-4027-aeb6-753775e19757.html
DataSet ds = new DataSet();
public int resultCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
OleDbCommand cmd = new OleDbCommand("select count(*) from email", cn);
cn.Open();
resultCount = Convert.ToInt32(cmd.ExecuteScalar());
cn.Close();
OleDbDataAdapter dr = new OleDbDataAdapter("select email from email", cn);
cn.Open();
dr.Fill(ds);
cn.Close();
}
//群发邮件
private void SendMyMail()
{
string FromMail = "liyou502@163.com"; //发件人
string Title = txtName.Text; // 邮件主题
string Body = txtMessage.Text; //邮件主体
string MailUserName = "liyou502"; //FromMail.Substring(0, FromMail.IndexOf( '@ '));
string MailPassword = "****"; //发件人邮箱密码
MailMessage mailmessage = new MailMessage();
MailAddress n = new MailAddress(FromMail);
mailmessage.From = n;
mailmessage.Subject = Title;
mailmessage.Body = Body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.Credentials = new System.Net.NetworkCredential(MailUserName, MailPassword);
try
{
string[] Receiver = new string[resultCount];//resultCount为数据库中的行数(无空值)
for (int i = 0; i < resultCount; i++)
{
Receiver[i] = ds.Tables[0].Rows[i]["email"].ToString();
}
for (int i = 0; i < resultCount; i++)
{
if (Receiver[i] == "")
{
Receiver[i] = "service_customer@163.com";
}
MailAddress to = new MailAddress(Receiver[i].ToString());
mailmessage.To.Add(to);
client.Send(mailmessage);
mailmessage.To.Clear();
Response.Write("成功发送!");
}
}
catch (Exception)
{
Response.Write(" <script language= 'javascript ' >alert( '邮件发送失败! ') </script >");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SendMyMail();
//Response.Write(" <script >alert ( 'Email envoyé avec succès ! ');location.href= 'index.aspx '; </script >");
}
}
for (int j = 0; j < Receiver.Length; j++)
{
mailmessage.To.Add(Receiver[j].ToString());
try
{
client.Send(mailmessage);
Response.Write("成功发送!");
}
这里会导致发送的邮件为(5+4+3+2+1(假如有5个地址)
下面的是改过的
不过还是有问题啊!
详见:http://topic.csdn.net/u/20071011/16/c5bbc8a6-321c-4027-aeb6-753775e19757.html
DataSet ds = new DataSet();
public int resultCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
OleDbCommand cmd = new OleDbCommand("select count(*) from email", cn);
cn.Open();
resultCount = Convert.ToInt32(cmd.ExecuteScalar());
cn.Close();
OleDbDataAdapter dr = new OleDbDataAdapter("select email from email", cn);
cn.Open();
dr.Fill(ds);
cn.Close();
}
//群发邮件
private void SendMyMail()
{
string FromMail = "liyou502@163.com"; //发件人
string Title = txtName.Text; // 邮件主题
string Body = txtMessage.Text; //邮件主体
string MailUserName = "liyou502"; //FromMail.Substring(0, FromMail.IndexOf( '@ '));
string MailPassword = "****"; //发件人邮箱密码
MailMessage mailmessage = new MailMessage();
MailAddress n = new MailAddress(FromMail);
mailmessage.From = n;
mailmessage.Subject = Title;
mailmessage.Body = Body;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";
client.Credentials = new System.Net.NetworkCredential(MailUserName, MailPassword);
try
{
string[] Receiver = new string[resultCount];//resultCount为数据库中的行数(无空值)
for (int i = 0; i < resultCount; i++)
{
Receiver[i] = ds.Tables[0].Rows[i]["email"].ToString();
}
for (int i = 0; i < resultCount; i++)
{
if (Receiver[i] == "")
{
Receiver[i] = "service_customer@163.com";
}
MailAddress to = new MailAddress(Receiver[i].ToString());
mailmessage.To.Add(to);
client.Send(mailmessage);
mailmessage.To.Clear();
Response.Write("成功发送!");
}
}
catch (Exception)
{
Response.Write(" <script language= 'javascript ' >alert( '邮件发送失败! ') </script >");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SendMyMail();
//Response.Write(" <script >alert ( 'Email envoyé avec succès ! ');location.href= 'index.aspx '; </script >");
}
}
#5
自己再顶
#6
学习。。。
#7
把要发送的东西(写成页面形式,内容用个字段替换用)存好,然后把发送的方法单独写在一个类里
然后替换循环发送就好了
然后替换循环发送就好了
#8
好象问了两个一样的问题
答案自然也应该一样
Membership user = Membership.GetAllUsers();//这里不懂怎么继续写,取出EMAIL??
======这句不懂什么意思
取出所有用户的email address直接查询数据库不就得了
将所有用户加上后send一下既可
答案自然也应该一样
Membership user = Membership.GetAllUsers();//这里不懂怎么继续写,取出EMAIL??
======这句不懂什么意思
取出所有用户的email address直接查询数据库不就得了
将所有用户加上后send一下既可