【摘要】
用了4个小时才整明白这么简单的一个东西,用gmail的企业邮箱怎么发信都不成功,最后终于发现了,原来是端口的问题.不能用465,要用587,天啊~,代码共享一下了
调用
Mailto.Mailto mail = new Mailto.Mailto("service@domin.com", "Hello", "test@test.com", "hello !!!!", "smtp.gmail.com", 587, true, "service@domin.com", "password");
if (mail.Send())
{
lc.WebMessageBox("Your Password Has Been Sent To Your Email", Page, true);
}
mailto类
namespace Mailto
{
using System;
using System.Net;
using System.Net.Mail;
【全文】
用了4个小时才整明白这么简单的一个东西,用gmail的企业邮箱怎么发信都不成功,最后终于发现了,原来是端口的问题.不能用465,要用587,天啊~,代码共享一下了
调用
Mailto.Mailto mail = new Mailto.Mailto("service@domin.com", "Hello", "test@test.com", "hello !!!!", "smtp.gmail.com", 587, true, "service@domin.com", "password");
if (mail.Send())
{
lc.WebMessageBox("Your Password Has Been Sent To Your Email", Page, true);
}
mailto类
namespace Mailto
{
using System;
using System.Net;
using System.Net.Mail;
public class Mailto
{
private MailMessage Mail = new MailMessage();
private SmtpClient SmtpServer = new SmtpClient();
public Mailto(string mFrom, string mSubjest, string mTo, string mBody, string mSmtpServer, int mSmtpPort, bool mSmtpSSL, string mUsername, string mPassword)
{
MailAddress mFromadd = new MailAddress(mFrom);
Mail.From = mFromadd;
Mail.Subject = mSubjest;
Mail.To.Add(mTo);
Mail.Body = mBody;
SmtpServer.Host = mSmtpServer;
SmtpServer.Port = mSmtpPort;
SmtpServer.EnableSsl = mSmtpSSL;
SmtpServer.UseDefaultCredentials = true;
SmtpServer.Credentials = new NetworkCredential(mUsername, mPassword);
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
}
public string mHtml(bool html)
{
Mail.IsBodyHtml = html;
if (html)
{
return "Html";
}
else
{
return "Text";
}
}
public bool Send()
{
try
{
SmtpServer.Send(Mail);
return true;
}
catch
{
return false;
}
}
}
}