程序如下: protected void Page_Load(object sender, EventArgs e)
{
if(Bind())
{
lblMailStatus.Text = "Mail successfully sent.";
}
//UPDATE STATUS
}
private bool Bind()
{
// CREATE A MAIL MESSAGE
System.Web.Mail.MailMessage myEmail = new System.Web.Mail.MailMessage();
// SET MESSAGE PARAMETERS
myEmail.From = "[email protected]";
myEmail.To = "[email protected]";
myEmail.Subject = "ceshiyoujian";
//myEmail.BodyFormat = System.Web.Mail.MailFormat.Html;
myEmail.Body = "The sunglasses you expressed interest in are now in stock.";
//SEND THE MESSAGE
System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com";
System.Web.Mail.SmtpMail.Send(myEmail); return true;
}错误:服务器拒绝发件人发送注:SmtpServer = "smtp.gmail.com"; outlook express 我已经设置好了,能接收到gmail的邮件,但是不知道放在程序里发邮件发不出去。 请大侠们指教,多谢!
{
if(Bind())
{
lblMailStatus.Text = "Mail successfully sent.";
}
//UPDATE STATUS
}
private bool Bind()
{
// CREATE A MAIL MESSAGE
System.Web.Mail.MailMessage myEmail = new System.Web.Mail.MailMessage();
// SET MESSAGE PARAMETERS
myEmail.From = "[email protected]";
myEmail.To = "[email protected]";
myEmail.Subject = "ceshiyoujian";
//myEmail.BodyFormat = System.Web.Mail.MailFormat.Html;
myEmail.Body = "The sunglasses you expressed interest in are now in stock.";
//SEND THE MESSAGE
System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com";
System.Web.Mail.SmtpMail.Send(myEmail); return true;
}错误:服务器拒绝发件人发送注:SmtpServer = "smtp.gmail.com"; outlook express 我已经设置好了,能接收到gmail的邮件,但是不知道放在程序里发邮件发不出去。 请大侠们指教,多谢!
解决方案 »
- 关于局部刷新问题
- 此帖必火!如何让<img>标签像Button控件一样回传和执行onclick
- 如控制textbox文本框长度,一边打字一边显示长度呢
- 紧急求助!.net调试问题,在线等待!!
- ASP.NET_文件操作_概念理解问题
- [问题]二进制流转化成对应的文件
- gridview的问题
- 这个有意思,每次打开都不一样
- [100分]求ms ajax中关于js 调用服务端代码的方法
- 大家帮帮忙吧,datagrid中的e.Item.Cells[9].Controls[0]总是不正确!
- 最近做了个.net网站,打开速度太慢,怎么办大家进来帮我看看
- visual studio 2005 在那里设置显示的行号
1 你的邮箱帐号不是VIP的
2 各家邮件服务器提供商对免费邮箱的SMTP处理机制不一样,基本上都有所限制,除了VIP
3 如果有时可以发有时不可以发,那是因为邮件服务器每次都判断发出邮件的地址频率很高或
是tom.com|sohu.com|163.com...其他邮件服务商的。如果是这样把该邮件判断成垃圾邮件或不受理的邮件 解决办法:
1 申请VIP邮箱,会开通通畅的SMPT,那就可以合法使用了
2 发邮件时,发出人邮箱地址的@后缀用随机算法(比如 是 [email protected]\[email protected]...)构造后再发出,
就可以解决问题。当然,这样做的毙命是收件人收到邮件后看到的发件人邮箱地址的@???就不是真实的,就说他无法
直接用该地址给回复邮件! 不知道我表达的是否清楚? 那还有其他方法:
1 自己去了解底层的邮件协议,像FOXMAIL那样做,内置邮件服务系统
2 自己构建邮件系统,第3方的
3 就是上面说的:@地址混淆法
适用于网站,因为收件人一般不会给网站回邮件,如果你要做FOXMAIL,那就要用1,2方法了!
//confusionFromMail:是否产生迷惑邮件服务器的邮件地址
//EncryptOption:是否加密邮件
//mailDESKey:加密邮件时的DES KEY
public static void SendMail(
string smtpHost, int smtpPort,
string smtpUser, string smtpPassword,
string fromMail, string sender,
string toMail, string receiver,
string subject, string body,
string attachment, string attachName,
bool smtpByIIS, bool smtpEnableSSL,
bool smtpEnableAuth, bool confusionFromMail, EncryptOption mailEncrypt, string mailDESKey
)
{
//Smtp Server
SmtpClient smtpServer = new SmtpClient(smtpHost, smtpPort);
smtpServer.UseDefaultCredentials = true;
if (smtpEnableAuth)
{
smtpServer.UseDefaultCredentials = false;
smtpServer.Credentials = new System.Net.NetworkCredential(smtpUser, smtpPassword);
}
smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpServer.EnableSsl = smtpEnableSSL; //Confusion Mail 产生迷惑邮件服务器的邮件地址
string frMail = fromMail;
if (confusionFromMail) frMail = BMailHelper.MakeConfusionMail(fromMail); //Mail Message
Encoding encoding = Encoding.GetEncoding("GB2312");
MailAddress fromMailAddress = new MailAddress(frMail, sender, encoding);
MailAddress toMailAddress = new MailAddress(toMail, receiver, encoding);
MailMessage mailMessage = new MailMessage(fromMailAddress, toMailAddress);
mailMessage.Priority = MailPriority.High; //Attachment
string encryptAttachment = EncryptHelper.SignatureAndEncrypt(attachment, mailDESKey, mailEncrypt);
System.Net.Mail.Attachment att = System.Net.Mail.Attachment.CreateAttachmentFromString(encryptAttachment, BFormatingMail.AttachName);
att.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
att.NameEncoding = encoding;
att.Name = attachName;
mailMessage.Attachments.Add(att); //Body
mailMessage.SubjectEncoding = encoding;
mailMessage.Subject = subject;
mailMessage.BodyEncoding = encoding;
mailMessage.Body = EncryptHelper.SignatureAndEncrypt(body, mailDESKey, mailEncrypt); //Sending
smtpServer.Send(mailMessage);
smtpServer.ServicePoint.CloseConnectionGroup(smtpServer.ServicePoint.ConnectionName);
} /// 产生迷惑邮件服务器的邮件地址
/// <param name="targetMail">发件地址.</param>
public static string MakeConfusionMail(string targetMail)
{
string s1 = BFormatingMail.GetEmailPart(targetMail, 1) ?? string.Empty; string[] domains = new string[] {
"asys.com", "aspt.com", "aast.com", "aaet.com",
"bsys.com", "bspt.com", "bast.com", "baet.com",
"csys.com", "cspt.com", "cast.com", "caet.com",
"dsys.com", "dspt.com", "dast.com", "daet.com",
"esys.com", "espt.com", "east.com", "eaet.com",
"fsys.com", "fspt.com", "fast.com", "faet.com",
"gsys.com", "gspt.com", "gast.com", "gaet.com",
"amou.com", "acat.com", "apig.com", "acar.com",
"bmou.com", "bcat.com", "bpig.com", "bcar.com",
"cmou.com", "ccat.com", "cpig.com", "ccar.com",
"dmou.com", "dcat.com", "dpig.com", "dcar.com",
"emou.com", "ecat.com", "epig.com", "ecar.com",
"fmou.com", "fcat.com", "fpig.com", "fcar.com",
"hmou.com", "hcat.com", "hpig.com", "hcar.com",
"imou.com", "icat.com", "ipig.com", "icar.com",
"jmou.com", "jcat.com", "jpig.com", "jcar.com",
"kmou.com", "kcat.com", "kpig.com", "kcar.com",
"lmou.com", "lcat.com", "lpig.com", "lcar.com",
"mmou.com", "mcat.com", "mpig.com", "mcar.com",
"nmou.com", "ncat.com", "npig.com", "ncar.com",
"ayal.com", "ayat.com", "aybt.com", "ayag.com",
"byal.com", "byat.com", "bybt.com", "byag.com",
"cyal.com", "cyat.com", "cybt.com", "cyag.com",
"dyal.com", "dyat.com", "dybt.com", "dyag.com",
"eyal.com", "eyat.com", "eybt.com", "eyag.com",
"fyal.com", "fyat.com", "fybt.com", "fyag.com",
"gyal.com", "gyat.com", "gybt.com", "gyag.com",
"hyal.com", "hyat.com", "hybt.com", "hyag.com",
"iyal.com", "iyat.com", "iybt.com", "iyag.com",
"jyal.com", "jyat.com", "jybt.com", "jyag.com",
"kyal.com", "kyat.com", "kybt.com", "kyag.com"
};
int index = (new Random()).Next(1, domains.Length);
if (index <= 0) index = 1;
string s2 = domains[index - 1];
return string.Format("{0}@{1}", s1, s2);
}
用jmail试试
_networkStream = new NetworkStream(_socket, true);
// 如果是走 ssl 方式
if (UseSsl)
{
//
SslStream sslStream = new SslStream(
_networkStream,
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),//
null
);
try
{
sslStream.AuthenticateAsClient(_proxy.TargetHost);
}
catch (System.Security.Authentication.AuthenticationException e)
{
string _lastError = e.Message;
if (e.InnerException != null)
{
_lastError += Environment.NewLine + e.InnerException.Message;
}
_networkStream.Close();
throw new SmtpException("Cannot create SSL tunnel to smtp host(" + _proxy.TargetHost + ":" + _proxy.TargetPort + ").", e);
} _streamReader = new StreamReader(sslStream, System.Text.Encoding.ASCII);
_streamWriter = new StreamWriter(sslStream, System.Text.Encoding.ASCII);
_streamWriter.AutoFlush = true;
}
else// 非 ssl 方式
{
_streamReader = new StreamReader(_networkStream, System.Text.Encoding.ASCII);
_streamWriter = new StreamWriter(_networkStream, System.Text.Encoding.ASCII);
_streamWriter.AutoFlush = true;
}
// 下面跟服务器的交互使用 streamReader streamWriter
// 好在 .net 封装 ssl stream static bool ValidateServerCertificate(
object sender,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
return true; //Console.WriteLine("验证错误: {0}", sslPolicyErrors); return false;
}
对, gmail 需要到网页的界面中打开 pop 功能才行.前几天测试收发都可以的.
端口号也不是默认的25,具体是什么忘了
pop3 是 995
smtp 是 465gamil web mail 的配置里头有说明.
就是在连接建立后, 交互开始之前, 做一下 ssl 认证.