C#发送邮件错误

viki117 2009-04-27 11:12:29

string SendEmail = "aijing117@163.com";//ds.Tables[0].Rows[0]["Address"].ToString();
string Sendsmtp = "smtp.163.com";//ds.Tables[0].Rows[0]["SMTP"].ToString();
string SendPass = "******";//ds.Tables[0].Rows[0]["PassWord"].ToString();

Encoding encoding = Encoding.Default;
MailAddress from = new MailAddress(SendEmail, "系统管理员", encoding);
MailAddress to = new MailAddress(recEmail);//
MailMessage mail = new MailMessage(from, to);
mail.Priority = MailPriority.High;
mail.IsBodyHtml = true;

mail.Subject = "用户取回密码";
mail.Body = "尊敬的" + UserName + ":您的密码是:" + password + ",请记住您的密码,千万不要泄露给他人,谢谢您使用我们的系统~!";
mail.SubjectEncoding = encoding;
mail.BodyEncoding = encoding;
SmtpClient smtp = new SmtpClient();
smtp.Host = Sendsmtp;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new System.Net.NetworkCredential(SendEmail, SendPass);
smtp.Timeout = 100000;
smtp.Send(mail);

代码应该没有什么问题,我已经对过N次了。。
但是一执行就出错误:
"事务失败。 服务器响应为: DT:SPM 309, smtp4, DtGowLD7GHr+EvVJSED+Aw--.18745S2 1240797951 http://mail.163.com/help/help_spam_16.htm?ip=989775938&hostid=smtp4&time=1240797951"
我也不明白这到底是什么错误,在错误列表中也没有发现这个提示
...全文
329 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzalec 2009-12-22
  • 打赏
  • 举报
回复
遇到了跟楼主一样的问题,试了好长时间
才发现 “系统管理员”等敏感字眼
所以呢
修改MailAddress from = new MailAddress(SendEmail, "系统管理员", encoding);
“系统管理员”改成其他值
viki117 2009-04-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 llsen 的回复:]
引用 1 楼 FantasyFreed 的回复:
163的smtp好像不能用了,推荐用换个邮箱。最好GMAIL的

不是吧
没问题的,可能是其他问题

试试这个

C# codeusing 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 Dat…
[/Quote]

要说你的代码测试是过去了,可是我也不知道你的代码和我差在那里,
就差在那些HTML之类的设置上了。。
看样子我要一个一个去掉看看
viki117 2009-04-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 cryeyes 的回复:]
163 smtp function need register before 2005
[/Quote]
要说注册,我应该是2001年注册的,
我换了个新注册SINA的,测试过去了。。
不知道为什么
llsen 2009-04-27
  • 打赏
  • 举报
回复
你这个可能是自动回复
还有可能就是发送时间间隔太短了

上面我的代码发送,没问题
但是我把定时器设的时间短的话
前面发可以,过段就不行了

这是网易防止恶意刷新的操作而已。
成都慢生活 2009-04-27
  • 打赏
  • 举报
回复
163 smtp function need register before 2005
llsen 2009-04-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 FantasyFreed 的回复:]
163的smtp好像不能用了,推荐用换个邮箱。最好GMAIL的
[/Quote]
不是吧
没问题的,可能是其他问题

试试这个
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");
}
}
yiyizhengli 2009-04-27
  • 打赏
  • 举报
回复
本机的组件注册是不是有问题呢?
FantasyFreed 2009-04-27
  • 打赏
  • 举报
回复
163的smtp好像不能用了,推荐用换个邮箱。最好GMAIL的
viki117 2009-04-27
  • 打赏
  • 举报
回复
哎哎,找不出为什么。。结帖子先。。
居然有发出去,就是成功了

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧