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; //发送失败
}
}知道利用这个方法可以发邮件,谁帮讲个这个方法的原理,最好是那种带有图的,为什么发完,发件箱里是查不到发出的邮件的?
解决方案 »
- session面试题
- 用Repeater绑定数据,怎么让里面绑定的数据一起向上滚动
- 这个语句不能用
- 各位老大帮个忙
- 请教:语句string R_LWID = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();的意思?谢谢!!!
- 在学做论坛,有点问题
- 通过FTP读服务器上的txt文件后,如何把文件内容存到数据库中?
- 再问将datagrid里的数据导出到excel的问题!!!
- 怎样让linkButton失去连接功能!!即当鼠标移到它的上面时不再出现小手状的图标
- 把datagrid的数据导入*.xls,并把结果文件保存到客户端该如何实现?
- 求助:事务提交两次后报错
- 关于验证码的刷新
就是一个接口的调用过程