代码如下:public static void SendActiveMail(string userID,string userMail,string userActiveCode)
{
SmtpSection smtpSec = NetSectionGroup.GetSectionGroup(WebConfigurationManager.OpenWebConfiguration("~/web.config")).MailSettings.Smtp; //直接使用webconfigurationmanager直接读取web.config里的节点
System.Net.Mail.MailMessage m_message = new System.Net.Mail.MailMessage();
m_message.To.Add(new MailAddress(userMail));
m_message.Subject = "激活邮件";
m_message.SubjectEncoding = System.Text.Encoding.UTF8;
m_message.Body = "您好,您的会员注册已经完成,只需最后一步激活后即可使用,请单击以下的链接完成用户激活。如链接失效,请直接复制http及以后的内容到浏览器直接访问。\nhttp://wtfc.cc/UserOp/UserActive.aspx?UserID="+userID+"&UserActive="+userActiveCode;
m_message.BodyEncoding = System.Text.Encoding.UTF8;
SmtpClient m_smtpClient = new SmtpClient();
m_smtpClient.EnableSsl = true; //注意这一句,gmail这样的需要允许SSL的邮箱必须要,否则会报错
m_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
m_smtpClient.Credentials = new System.Net.NetworkCredential(smtpSec.Network.UserName,smtpSec.Network.Password);
m_smtpClient.Send(m_message);
}
当我注册万用户后,点击提交 总是出现如下错误: 由于目标机器积极拒绝,无法连接。 123.125.50.135:23
{
SmtpSection smtpSec = NetSectionGroup.GetSectionGroup(WebConfigurationManager.OpenWebConfiguration("~/web.config")).MailSettings.Smtp; //直接使用webconfigurationmanager直接读取web.config里的节点
System.Net.Mail.MailMessage m_message = new System.Net.Mail.MailMessage();
m_message.To.Add(new MailAddress(userMail));
m_message.Subject = "激活邮件";
m_message.SubjectEncoding = System.Text.Encoding.UTF8;
m_message.Body = "您好,您的会员注册已经完成,只需最后一步激活后即可使用,请单击以下的链接完成用户激活。如链接失效,请直接复制http及以后的内容到浏览器直接访问。\nhttp://wtfc.cc/UserOp/UserActive.aspx?UserID="+userID+"&UserActive="+userActiveCode;
m_message.BodyEncoding = System.Text.Encoding.UTF8;
SmtpClient m_smtpClient = new SmtpClient();
m_smtpClient.EnableSsl = true; //注意这一句,gmail这样的需要允许SSL的邮箱必须要,否则会报错
m_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
m_smtpClient.Credentials = new System.Net.NetworkCredential(smtpSec.Network.UserName,smtpSec.Network.Password);
m_smtpClient.Send(m_message);
}
当我注册万用户后,点击提交 总是出现如下错误: 由于目标机器积极拒绝,无法连接。 123.125.50.135:23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Net.Mail;
using System.Net;/// <summary>
///sendEmail 的摘要说明
/// </summary>
public class sendEmail
{
public sendEmail()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 向用户发送邮件
/// </summary>
/// <param name="receiveUser">接收邮件的用户</param>
/// <param name="sendUser">发送者</param>
/// <param name="sendusername">发送者的邮箱登陆名</param>
/// <param name="userpassword">发送者的登陆密码</param>
/// <param name="sendTitle">发送标题</param>
/// <param name="sendContent">发送的内容</param>
/// <returns></returns>
public void sendMail(string receiveUser, string sendUser, string sendusername, string userpassword, string sendTitle, string sendContent)
{
MailAddress to = new MailAddress(receiveUser);//接收者邮箱
MailAddress from = new MailAddress(sendUser);//发送者邮箱
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(from, to);
//mail.To.Add("[email protected]");//添加接收者 mail.Subject = sendTitle;
mail.IsBodyHtml = true;
mail.Body = sendContent;
SmtpClient client = new SmtpClient();
client.Host = "smtp.163.com";//设置发送者邮箱对应的smtpserver
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(sendusername, userpassword);//设置发送者邮箱对应的username和password
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(mail);
}}//btn事件
sendEmail se = new sendEmail();
// se.sendMail("[email protected]","wj","zhao88","9523","您好测试","测试中");
se.sendMail("[email protected]", "[email protected]", "lie_a", "8088", "千机购物重设密码信", "aa");
System.Windows.Forms.MessageBox.Show("发送成功");//引用空间名:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Net.Mail;
using System.Net;