为什么现在很多SMPT账号用system.net.mail.mailmessage发不邮件?【新注册居然给不了分,晕,明天补上。】
之前我一直是用system.net.mail.mailmessage这个类发邮件,这几天突然发不了,排除账号密码错误问题。很是郁闷,同个账号,绝对是支持SMTP的,因为我用IMAP软件测试过没有问题,甚至,同样的账号,在PHP的邮件发送程序都是正常发信的,但就是在.NET里发不了,但以前一直用得好好的。
后来经测试,163.COM的还可以正常发信,但为什么其它FOXMAIL.COM,QQ.COM,GMAIL.COM等都发不了了呢,错误提示“由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。”
居然给不了分,晕,明天补上。
邮件发送的代码如下:
public static bool SendMail(string to, string subject, string body, bool isHtml)--------------------编程问答-------------------- 顶起。
{
MailMessage mail = new MailMessage("a@a.com", to);
mail.From = new MailAddress(ConfigurationManager.AppSettings["SmtpSender"],
ConfigurationManager.AppSettings["DisplayName"]);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = isHtml;
SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings["SmtpServer"];
smtp.Port = int.Parse(ConfigurationManager.AppSettings["SmtpPort"]);
System.Net.NetworkCredential credential = new System.Net.NetworkCredential();
credential.UserName = ConfigurationManager.AppSettings["SmtpUsername"];
credential.Password = ConfigurationManager.AppSettings["SmtpPin"];
smtp.Credentials = credential;
try
{
smtp.Send(mail);
return true;
}
catch (SmtpException)
{
return false;
}
}
【新注册居然给不了分,晕,明天补上。】 --------------------编程问答-------------------- private void mailTo(string MailTo, string MailSubject, string MailBody)
{
string errMsg = string.Empty;
m_MailSend = new Send();
try
{
m_MailSend.MailServer = "SMTP.163.com";
m_MailSend.MailServerAcc = "163账号";
m_MailSend.MailServerPWD = "账号密码";
m_MailSend.MailFrom = "账号@163.com";
m_MailSend.MailTo = MailTo;
if (m_MailSend.SendMail(MailSubject, MailBody, "", ref errMsg))
{
//MessageBox.Show("发送成功!");
}
else
{
//MessageBox.Show("发送失败:\r\n" + errMsg);
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}
} --------------------编程问答-------------------- 顶起,现在有分了。 --------------------编程问答--------------------
using System.Net.Mail;
using System.Net.Mime;
using System.Net;
public static void CreateMessageWithAttachment(string server)
{
// Specify the file to be attached and sent.
// This example assumes that a file named Data.xls exists in the
// current working directory.
string file = @"D:\asdf.txt";
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"asdf@163.com",
"asdf@163.com",
"test",
"no du");
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
//Send the message.
SmtpClient client = new SmtpClient(server);
// Add credentials if the SMTP server requires them.
//client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential("username", "password");
client.Send(message);
// Display the values in the ContentDisposition for the attachment.
ContentDisposition cd = data.ContentDisposition;
Console.WriteLine("Content disposition");
Console.WriteLine(cd.ToString());
Console.WriteLine("File {0}", cd.FileName);
Console.WriteLine("Size {0}", cd.Size);
Console.WriteLine("Creation {0}", cd.CreationDate);
Console.WriteLine("Modification {0}", cd.ModificationDate);
Console.WriteLine("Read {0}", cd.ReadDate);
Console.WriteLine("Inline {0}", cd.Inline);
Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
foreach (DictionaryEntry d in cd.Parameters)
{
Console.WriteLine("{0} = {1}", d.Key, d.Value);
}
data.Dispose();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
if (DateTime.Now.Second % 20 == 0)
{
CreateMessageWithAttachment("smtp.163.com");
}
}
有些可能是邮件服务器问题 --------------------编程问答-------------------- FOXMAIL.COM,QQ.COM,GMAIL.COM好像普遍都存在这个问题,很多都是一开始能发,然后过了一段时间后就不行了,用163和新浪的都没问题 --------------------编程问答--------------------
那到底是什么原因啊,一直都用在用foxmail.com,qq.com的,快两年了,现在才遇发不出的情况。
为什么PHP,IMAP软件可以发呢,我怀疑是代码有问题,或许还有一些属性没有显式(明显的)设置什么的。 --------------------编程问答--------------------
不好意思,我也不知道为什么,我只知道存在这个情况,如何解决我也没辙 --------------------编程问答-------------------- 真纳闷。。。 --------------------编程问答-------------------- 账号新旧差别待遇而已.
现在新注册的126账号也不能发. --------------------编程问答-------------------- 估计是POP3功能设置问题。因为163新开通的帐号,不能使用POP功能,也不能使用软件接收发送邮件。 --------------------编程问答--------------------
感谢关注,但你看我的原话,根本与账号无关。
补充:.NET技术 , ASP.NET