我用asp.net 2.0写了一段代码,为什么总是发送不出去
不知道是那块服务配的不对,还是参数传的不对,
代码如下:
/// <summary>
/// 发送电子邮件函数
/// </summary>
/// <param name="host"></param>
/// <param name="userName"></param>
/// <param name="pwd"></param>
/// <param name="ssl"></param>
/// <param name="from">电子邮件发件人的地址</param>
/// <param name="to">电子邮件收件人的地址</param>
/// <param name="subject">电子邮件主题</param>
/// <param name="body">电子邮件正文</param>
/// <returns></returns>
public static int sendMail(string host, string userName, string pwd, bool ssl, string from, string to, string subject, string body)
{
System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
mail.Host = host;//smtp
//mail.Credentials = new System.Net.NetworkCredential(userName, pwd);
//mail.EnableSsl = ssl;//发送连接套接层是否加密 例如用gmail发是加密的
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
message.Body = body;
message.Subject = subject;
message.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");
message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
message.IsBodyHtml = true;
try
{
mail.Send(message);
return 0;
}
catch (Exception ex)
{
return 1;
}
}
/// 发送电子邮件函数
/// </summary>
/// <param name="host"></param>
/// <param name="userName"></param>
/// <param name="pwd"></param>
/// <param name="ssl"></param>
/// <param name="from">电子邮件发件人的地址</param>
/// <param name="to">电子邮件收件人的地址</param>
/// <param name="subject">电子邮件主题</param>
/// <param name="body">电子邮件正文</param>
/// <returns></returns>
public static int sendMail(string host, string userName, string pwd, bool ssl, string from, string to, string subject, string body)
{
System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
mail.Host = host;//smtp
//mail.Credentials = new System.Net.NetworkCredential(userName, pwd);
//mail.EnableSsl = ssl;//发送连接套接层是否加密 例如用gmail发是加密的
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
message.Body = body;
message.Subject = subject;
message.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");
message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
message.IsBodyHtml = true;
try
{
mail.Send(message);
return 0;
}
catch (Exception ex)
{
return 1;
}
}
我的参数是这么传的:
sendMail("smtp.163.com", "puke_840928", "*****", false, "
puke_840928@163.com", "
jxiang666@163.com", "你好", "正文");