需要一个群发邮件的代码
希望能有细一点的注释.谢谢了 --------------------编程问答-------------------- SmtpClient mailServer = new SmtpClient();mailServer.Host = Host;
mailServer.Port = Port;
mailServer.EnableSsl = EnableSsl;
mailServer.UseDefaultCredentials = false;
mailServer.Credentials = new NetworkCredential(UID, PWD);
mailServer.Timeout = Timeout;
mailServer.Timeout = Timeout;
MailAddress from = new MailAddress(姓名<電子郵件>);
MailAddress to = new MailAddress(姓名<電子郵件>;姓名<電子郵件>);
MailMessage message = new MailMessage(from, to);
message.Subject = email.Subject;
message.CC.Add(姓名<電子郵件>;姓名<電子郵件>);
message.Bcc.Add(姓名<電子郵件>;姓名<電子郵件>);
message.Body = email.Body;
foreach (string atta in attas)
{
Attachment attachment = new Attachment(atta);
message.Attachments.Add(attachment);
}
message.SubjectEncoding = ConfigManager.MailEncoding;
message.BodyEncoding = ConfigManager.MailEncoding;
message.IsBodyHtml = true;
try
{
mailServer.Send(_message); --------------------编程问答-------------------- 利用JMAIL组件吧,很不错的说
然后在类中using jamil;
然后声明
jmail.MessageClass MsgMail = new jmail.MessageClass();
MsgMail.Logging = true;
MsgMail.Silent = true;
MsgMail.Charset = "GB2312"; //设置邮件的编码方式
MsgMail.Encoding = "Base64"; //设置邮件的附件编码方式
MsgMail.ISOEncodeHeaders = false; //是否将信头编码成iso-8859-1字符集
MsgMail.From = "签名,显示是谁发的";
MsgMail.FromName = "发送邮件的邮箱的用户名,显示是哪个邮箱发的";
MsgMail.MailServerUserName = "发送邮件的邮箱的用户名";
MsgMail.MailServerPassWord = "发送邮件的邮箱密码";
//加收件人
MsgMail.AddRecipient("收件人的地址,可添加多个,重复调用就可以了",null,null);
//加抄送人
MsgMail.AddRecipientCC("收件人的地址,可添加多个,重复调用就可以了",null,null);
//加暗送人
MsgMail.AddRecipientBCC("收件人的地址,可添加多个,重复调用就可以了",null);
MsgMail.Subject = "标题";
MsgMail.Body = "正文";
MsgMail.AddAttachment(文件的物理路径,false,文件的类型,例如:text/plain表示txt文档);
if(MsgMail.Send(Session["SMTPSvr"].ToString(), false))
{
Response.Redirect("./ErrorPage.aspx?error=邮件已经成功发送!");
}
else
{
Response.Redirect("./ErrorPage.aspx?error=发送失败!");
} --------------------编程问答-------------------- 其实要看你怎么发了,System.Net.Mail 和System.Web.Mail两个组件都能发邮件
System.Web.Mail发送不需要服务器
System.Net.Mail可以借用别人的服务器比如163,gmail什么的,具体代码网上一搜一大堆 --------------------编程问答-------------------- /// <summary>
/// 发送邮件,不能发送附件。
/// </summary>
/// <param name="send">发件人地址</param>
/// <param name="recieve">收件人地址</param>
/// <param name="subject">邮件主题</param>
/// <param name="mailbody">邮件内容允许是html</param>
/// <param name="host">发件主机</param>
/// <param name="pwd">密码</param>
public void SendMailUseGmail(string send, string recieve, string subject, string mailbody, string host, string pwd,Page page)
{
try
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = host;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(send, pwd);
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add(recieve); message.From = new System.Net.Mail.MailAddress(send, "派遣168网", System.Text.Encoding.UTF8);
message.Subject = subject;
message.Body = mailbody;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
//添加附件
//System.Net.Mail.Attachment data = new Attachment(@"附件地址如:e:\a.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
//message.Attachments.Add(data);
client.Send(message);
System.Web.UI.ScriptManager.RegisterStartupScript(page, this.GetType(), "success", "alert('邮件发送成功!');", true);
}
catch (Exception ex)
{
System.Web.UI.ScriptManager.RegisterStartupScript(page, this.GetType(), "eeror", "alert('邮件发送失败!"+ex.Message+"');", true);
}
}
补充:.NET技术 , ASP.NET