邮件发送问题,请高手帮忙
邮件发送代码如下:
private bool SendMailFun(string txt_From,string txt_To,string txt_Cc,
string txt_Subject,string txt_Body,string txt_Attachment,
string cmb_Priority,string cmb_Format)
{
try
{
MailMessage myMail = new MailMessage();
myMail.From = txt_From.Trim(); //设置发件人
myMail.To = txt_To.Trim(); //设置收件人
myMail.Cc = txt_Cc.Trim(); //设置抄送
myMail.Subject = txt_Subject.Trim(); //设置邮件主题
myMail.Body = txt_Body.Trim(); //设置邮件正文
//添加附件
txt_Attachment=txt_Attachment.Trim();
if(txt_Attachment.Substring(txt_Attachment.Length-1,1)==",")
txt_Attachment=txt_Attachment.Substring(0,txt_Attachment.Length -1);
if (txt_Attachment.Trim() != "")
{
char[] delim = new char[] {','};
foreach (string att in txt_Attachment.Trim().Split(delim))
{
MailAttachment myAttachment = new MailAttachment(att);
myMail.Attachments.Add(myAttachment);
}
}
//设置邮件优先级
if (cmb_Priority == "高")
myMail.Priority = MailPriority.High;
else if (cmb_Priority == "低")
myMail.Priority = MailPriority.Low;
else
myMail.Priority = MailPriority.Normal;
//设置邮件格式
if (cmb_Format == "Html格式")
myMail.BodyFormat = MailFormat.Html;
else
myMail.BodyFormat = MailFormat.Text;
myMail.Fields.Add(CDO.CdoConfiguration.cdoSMTPAuthenticate,"1");
myMail.Fields.Add(CDO.CdoConfiguration.cdoSendUserName,txt_Email.Text.Trim()); //用户名
myMail.Fields.Add(CDO.CdoConfiguration.cdoSendPassword,txt_Psd.Text); //密码
SmtpMail.SmtpServer=txt_Smtp.Text;
SmtpMail.Send(myMail); //发送邮件
return true;
}
catch(Exception ex)
{
return false;
}
我目前测试是用163邮箱,SMTP为:smtp.163.com
昨天我能成功的连续发送70封邮件,以后就一直发送失败;
可今天成功的连续发送30封邮件,以后就一直发送失败.
不知是什么原因?
-----连发代码如下:----------
for(int i=1;i<dataSet.Tables[0].Rows.Count;i++)
{
SendMailFun(txt_From,txt_To,txt_Cc,txt_Subject,txt_Body,
txt_Attachment,cmb_Priority,cmb_Format);
}
---------------------------
------解决方案--------------------不晓得 帮顶了
------解决方案--------------------可能是163服务那里设置原因,将发送邮件时间间隔改一下看看
------解决方案--------------------Threading名称空间中找吧