public static int SendEmail(string mto, string msubject, string mbody, string MyMail, string mailPass)
{ string from = MyMail;
string pwd = mailPass; string to = mto.Trim();
MailMessage mail = new MailMessage(from, to);
mail.Subject = msubject;
mail.SubjectEncoding = System.Text.Encoding.GetEncoding("UTF-8");
mail.Body = mbody;
mail.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8");
mail.IsBodyHtml = true;
string server = "";
int port = 25;
if (from.IndexOf("@gpres") != -1 || from.IndexOf("@gmail") != -1)
{
port = 587;
server = "smtp.gmail.com";
}
else
{
port = 25;
string temp;
temp = from.Substring(from.LastIndexOf('@') + 1);
server = "smtp." + temp;
}
SmtpClient sc = new SmtpClient(server, port);
if (port != 25)
{
sc.EnableSsl = true;
}
sc.Credentials = new NetworkCredential(from, pwd); try
{
sc.Send(mail);
mail.Dispose();
return 1; //发送成功
}
catch (Exception ex)
{
//System.Web.HttpContext.Current.Response.Write(e.Message);
mail.Dispose();
return 0; //发送失败
}
}知道利用这个方法可以发邮件,谁帮讲个这个方法的原理,最好是那种带有图的,为什么发完,发件箱里是查不到发出的邮件的?
{ string from = MyMail;
string pwd = mailPass; string to = mto.Trim();
MailMessage mail = new MailMessage(from, to);
mail.Subject = msubject;
mail.SubjectEncoding = System.Text.Encoding.GetEncoding("UTF-8");
mail.Body = mbody;
mail.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8");
mail.IsBodyHtml = true;
string server = "";
int port = 25;
if (from.IndexOf("@gpres") != -1 || from.IndexOf("@gmail") != -1)
{
port = 587;
server = "smtp.gmail.com";
}
else
{
port = 25;
string temp;
temp = from.Substring(from.LastIndexOf('@') + 1);
server = "smtp." + temp;
}
SmtpClient sc = new SmtpClient(server, port);
if (port != 25)
{
sc.EnableSsl = true;
}
sc.Credentials = new NetworkCredential(from, pwd); try
{
sc.Send(mail);
mail.Dispose();
return 1; //发送成功
}
catch (Exception ex)
{
//System.Web.HttpContext.Current.Response.Write(e.Message);
mail.Dispose();
return 0; //发送失败
}
}知道利用这个方法可以发邮件,谁帮讲个这个方法的原理,最好是那种带有图的,为什么发完,发件箱里是查不到发出的邮件的?
解决方案 »
- asp.net实现oracle更改出错,提示ORA-00911: 无效字符
- Razor 后台如何动态调用javascript,如(Page.RegisterStartupScript)
- 我要写一个类似支付宝登录时用的密码自定义控件
- asp.net 开发视频网站,如何限制会员的流量?
- 当dropdownlist为空回显示很长的百区域??怎么办???
- 再次提问,关于获取局域网内客户端硬件配置
- 装vs.net的烦恼,望大侠帮助解决。
- TreeView 无刷新问题
- 我想在TextBox里面输入物资的上标和下标,例如:M2 平方米,请问如何实现呀,试了很久了,还是不行,请问那位有好的办法?
- 求ASP.NET(C#)写的留言本或论坛源代码参考!
- 求助:事务提交两次后报错
- 关于验证码的刷新
就是一个接口的调用过程