关于SMTP发送邮件出现的问题(asp.net)
问:
1.首先,你们知道邮件服务器在哪里设置smtp吗?
2.网上的2种方法我都设置了,能用163的邮箱发(163.com),但是其他的都不行(QQ,126等),为什么呀?程序如下:
方法1:
//发送邮件
public int SendMail(string strComment, string strSubject, string strEmailTo) //strComment 为邮件内容,strSubject 主题,strEmailTo为 收件人的地址
{
int li_Return = 0;
string ls_ErrText = " ";
try
{
DataAccess.Emails emailObj = new DataAccess.Emails();
DataTable dtNew = new DataTable();
li_Return = emailObj.GetEmails(dtNew, ref ls_ErrText);
if (li_Return <= 0)
{
ClientScript.RegisterStartupScript( " ".GetType(), "KeyError ", " <script language= 'javascript '> alert( '获取邮件地址失败! ');parent.f_Submit(); </script> ");
}
MailMessage objMailMessage = new MailMessage();
objMailMessage.From = new MailAddress(dtNew.Rows[0][ "EMail "].ToString()); //邮箱地址 support@biz369.com
objMailMessage.Subject = strSubject;
objMailMessage.SubjectEncoding = System.Text.Encoding.Default;
objMailMessage.Body = strComment;
objMailMessage.BodyEncoding = System.Text.Encoding.Default;
objMailMessage.IsBodyHtml = true;
objMailMessage.To.Add(strEmailTo);
SmtpClient client = new SmtpClient(dtNew.Rows[0][ "SMTP "].ToString());// IP 或 SMTP.josson.com
client.UseDefaultCredenti