通常我们遇到的错误是:\'The message was undeliverable. All servers failed to receive the message \',这其实是JMAIL返回的错误,并不是ASP代码产生的,根本原因是MAIL SERVER拒绝了JMAIL的请求.
究其原因,是那些服务器不提供SMTP服务或者没有开启smtp服务或是在服务器端开启了\'禁止邮件中继服务\'选项,也就是说不在其允许的IP段或指定范围内的空间里的程序是无法使用其SMTP服务的,最终导致\'8000ffff\'错误发生。
可以参考这个看
public void SendEmail(string filetype, StiReport report, string fromaddress, string toaddress, string subject, string messageBody, string host, int port, string username, string password){
try
{
using (MemoryStream ms = new MemoryStream())
{
string filename = ""
StiExportFormat sef = StiExportFormat.Pdf
GetFormat(filetype, ref sef, ref filename)
report.ExportDocument(sef, ms)
ms.Seek(0, SeekOrigin.Begin)
//使用自己的邮件发送机制
System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(ms, filename)
MailMessage item = new MailMessage(fromaddress, toaddress)
item.Subject = subject
item.Body = messageBody
item.Attachments.Add(attachment)
SmtpClient smtp = new SmtpClient(host, port)
smtp.UseDefaultCredentials = false
smtp.Credentials = new System.Net.NetworkCredential(username, password)
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
smtp.Send(item)
ms.Close()
}
}
catch
{
ClientScript.RegisterStartupScript(GetType(), "", "<script>showerror()</script>")
}
ClientScript.RegisterStartupScript(GetType(), "", "<script>showmessage()</script>")
}
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)