using System;
using System.Text;
using System.Net;
using System.Net.Mail;
using BLL.Config;
/// <summary>
/// 发送email的类
/// </summary>
public class Email
{
private string _sendaddress;
private string _sendname;
private string _getaddress;
private string _smtp;
private string _uid;
private string _pwd;
private string _title;
private string _body; public Email()
{
Config cfg = new Config();
cfg.Initform();
this._sendaddress = cfg.email_sendaddress;
this._pwd = cfg.email_pwd;
this._smtp = cfg.email_smtp;
this._uid = cfg.email_uid;
this._sendname = cfg.email_sendname; }
/// <summary>
/// 收件地址
/// </summary>
public string Getaddress
{
set { _getaddress = value; }
}
/// <summary>
/// 标题
/// </summary>
public string Title
{
set { _title = value; }
}
/// <summary>
/// 内容
/// </summary>
public string Body
{
set { _body = value; }
} public bool send()
{
try
{
//编码暂硬性规定为GB2312
Encoding encoding = Encoding.GetEncoding(936);
MailMessage Message = new MailMessage(
new MailAddress(_sendaddress, _sendname, encoding),//第一个是发信人的地址,第二个参数是发信人
new MailAddress(_getaddress));//收信人邮箱
Message.SubjectEncoding = encoding;
Message.Subject = _title;//标题
Message.BodyEncoding = encoding;
Message.Body = _body; //主体
SmtpClient smtpClient = new SmtpClient(_smtp);//信箱服务器
smtpClient.Credentials = new NetworkCredential(_uid, _pwd);//信箱的用户名和密码
smtpClient.Timeout = 999999;
smtpClient.Send(Message);
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
return false;
}
}
}
为何不能实现自动发邮件
using System.Text;
using System.Net;
using System.Net.Mail;
using BLL.Config;
/// <summary>
/// 发送email的类
/// </summary>
public class Email
{
private string _sendaddress;
private string _sendname;
private string _getaddress;
private string _smtp;
private string _uid;
private string _pwd;
private string _title;
private string _body; public Email()
{
Config cfg = new Config();
cfg.Initform();
this._sendaddress = cfg.email_sendaddress;
this._pwd = cfg.email_pwd;
this._smtp = cfg.email_smtp;
this._uid = cfg.email_uid;
this._sendname = cfg.email_sendname; }
/// <summary>
/// 收件地址
/// </summary>
public string Getaddress
{
set { _getaddress = value; }
}
/// <summary>
/// 标题
/// </summary>
public string Title
{
set { _title = value; }
}
/// <summary>
/// 内容
/// </summary>
public string Body
{
set { _body = value; }
} public bool send()
{
try
{
//编码暂硬性规定为GB2312
Encoding encoding = Encoding.GetEncoding(936);
MailMessage Message = new MailMessage(
new MailAddress(_sendaddress, _sendname, encoding),//第一个是发信人的地址,第二个参数是发信人
new MailAddress(_getaddress));//收信人邮箱
Message.SubjectEncoding = encoding;
Message.Subject = _title;//标题
Message.BodyEncoding = encoding;
Message.Body = _body; //主体
SmtpClient smtpClient = new SmtpClient(_smtp);//信箱服务器
smtpClient.Credentials = new NetworkCredential(_uid, _pwd);//信箱的用户名和密码
smtpClient.Timeout = 999999;
smtpClient.Send(Message);
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
return false;
}
}
}
为何不能实现自动发邮件
测试用163或者新浪的 smtp 设定都没有问题,能发送,唯独用万网的企业邮箱无法实现,纠结了2天了,郁闷中
帮我看看是代码哪里设定的问题吗
谢谢