求一asp.net发送邮件的方法。
用.net自带的也可,jmail组件也可!最好能说明各种方法需要系统怎么配置!谢谢!
用.net自带的也可,jmail组件也可!最好能说明各种方法需要系统怎么配置!谢谢!
解决方案 »
- 如何使用 JS 获取带的CheckBox的 TreeView 最后一级节点的值..
- 请教一个问题,下面的错误要怎么看,是什么问题?谢谢了...
- ◆如何获取devexpress中的TreeList控件勾选项的值(winform)◆
- asp.net跨线程操作!麻烦各位高手及专家!谢谢!
- 提一个关于GirdView的RowCommand中的e.CommandSource问题.
- 关于HTML设计器被缩放??
- gridview控件的数据源为存储过程时,怎样去编辑列,定义列的属性?
- 程序员的最后归宿究竟是什么?
- 用DataAdapter来插入记录有没有办法得到数据库的自动增量ID?
- 弹出有模式页面问题!急用!
- 在Asp.net web开发中添加图片水印的方法
- 母版页使用树形控件的问题!!紧急求助!
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="SmtpServer">发件邮箱服务器</param>
/// <param name="PassWord">发件人邮箱密码</param>
/// <param name="SendMail">发件人邮箱</param>
/// <param name="SendName">发件人在邮件中的显示名</param>
/// <param name="ReceiverMail">收件人邮箱</param>
/// <param name="ReceiverName">收件人在邮箱中的显示名</param>
/// <param name="MailSubject">邮件标题</param>
/// <param name="MailBody">邮件正文</param>
/// <param name="Attachments">附件路径</param>
/// <returns></returns>
public bool SendMail(string SmtpServer, string PassWord, string SendMail, string SendName, string ReceiverMail, string ReceiverName, string MailSubject, string MailBody, string Attachments)
{
System.Net.Mail.SmtpClient smtp;
smtp = new System.Net.Mail.SmtpClient(SmtpServer);
smtp.Timeout = 60000;
smtp.UseDefaultCredentials = true;
//设置发件人用户密码
smtp.Credentials = new System.Net.NetworkCredential(SendMail.Split('@')[0], PassWord);
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.BodyEncoding = System.Text.Encoding.UTF8;
//设置发件人地址姓名
message.From = new System.Net.Mail.MailAddress(SendMail, SendName, System.Text.Encoding.UTF8);
//设置收件人地址姓名
message.To.Add(new System.Net.Mail.MailAddress(ReceiverMail, ReceiverName, System.Text.Encoding.UTF8));
message.IsBodyHtml = true;
message.Subject = MailSubject;
message.Body = MailBody;
if (Attachments != "" && Attachments!=null)
message.Attachments.Add(new System.Net.Mail.Attachment(Attachments));
try
{
smtp.Send(message);
return true;
}
catch(Exception ex)
{
string mes=ex.Message;
return false;
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
public partial class sendMail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
////设置发件人信箱,及显示名字
MailAddress from = new MailAddress("[email protected]", "J.L.C");
//设置收件人信箱,及显示名字
MailAddress to = new MailAddress(TextBox1.Text, "JLC");
//创建一个MailMessage对象
MailMessage oMail = new MailMessage(from, to); oMail.Subject = TextBox2.Text; //邮件标题
oMail.Body = TextBox3.Text; //邮件内容 oMail.IsBodyHtml = true; //指定邮件格式,支持HTML格式
oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");//邮件采用的编码
oMail.Priority = MailPriority.High;//设置邮件的优先级为高 //发送邮件服务器
SmtpClient client = new SmtpClient();
client.Host = "smtp.126.com"; //指定邮件服务器
client.Credentials = new NetworkCredential("[email protected]", "jlc3509589934");//指定服务器邮件,及密码 //发送
try
{
client.Send(oMail); //发送邮件
Label1.Text = "恭喜你!邮件发送成功。";
}
catch
{
Label1.Text = "邮件发送失败,检查网络及信箱是否可用。";
} oMail.Dispose(); //释放资源 TABLE1.Visible = false;
Table2.Visible = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
//返回,继续发送
Response.Redirect(Request.Url.ToString());
TABLE1.Visible = true;
Table2.Visible = false;
}
}
public void MailSend(string MailFrom,string MailTo,string MailPwd,string Mailtitle,string MailCon)
{
MailMessage MyMail = new MailMessage();
MyMail.From = new MailAddress(MailFrom + "@163.com", "");
MyMail.To.Add(new MailAddress(MailTo + "@163.com"));
MyMail.Subject = Mailtitle;
MyMail.Body = MailCon;
MyMail.IsBodyHtml = false;
SmtpClient smtpclient = new SmtpClient();
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpclient.Host = "smtp.163.com";
smtpclient.Credentials = new System.Net.NetworkCredential(MailFrom, MailPwd);
smtpclient.Send(MyMail);
} jmail.Message Jmail = new jmail.Message();
DateTime t = DateTime.Now;
String Subject = "";
String body = "";
String FromEmail = "";
String ToEmail = "";
Jmail.Charset = "GB2312";
Jmail.ContentType = "text/html";
Jmail.AddRecipient(ToEmail, "", "");
Jmail.From = FromEmail;
Jmail.MailServerUserName = "";
Jmail.MailServerPassWord = "";
Jmail.Subject = Subject;
Jmail.ContentType="text/html";
Jmail.Body = body + t.ToString();
Jmail.Send("smtp.163.com", false);
Jmail.Close();参考
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using jmail;/// <summary>
/// JMail 的摘要说明
/// </summary>
public class JMail
{
public JMail()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string WithMail(string strFrom, string strEamilAcc, string password, string strTo, string strTitle, string strContent, Boolean boolSSL, string strSMTP)
{
jmail.Message myMail = new Message();
myMail.Charset = System.Text.Encoding.UTF8.ToString();//设定邮件字符集
myMail.ContentType = "text/HTML"; //设置这个头文件为“TEXT/HTML”发送HTML信息
myMail.Encoding = "UTF-8";
myMail.Priority = 5;//设置优先级别5最大1最小
myMail.From = strFrom;//发送方的EMAIL
myMail.AddRecipient(strTo,null,null);
myMail.MailServerUserName = strEamilAcc;//发送方的密码
myMail.MailServerPassWord = password;//发送方帐号密码
myMail.Subject = strTitle;//邮件的标题
myMail.Body = strContent;//邮件内容
myMail.Send(strSMTP, false); //邮件的SMTP地址
myMail.Silent = true;
return "返回内容~";//内容
}
}
.NET
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Text;/// <summary>
/// NetEmail 的摘要说明
/// </summary>
public class NetEmail
{
public NetEmail()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string witnEmail(string strFrom, string strEmailAcc, string strPass, string strTo, string strTitle, string strContent, Boolean boolSSL, string strSMTP)
{
MailMessage me = new MailMessage();
me.From = new MailAddress(strFrom, strEmailAcc);
me.To.Add(strTo);
me.Subject = strTitle;
me.Body = strContent;
me.BodyEncoding = UnicodeEncoding.UTF8;
me.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.EnableSsl = false;
client.Host = strSMTP;
client.Credentials = new System.Net.NetworkCredential(strEmailAcc, strPass);
client.Send(me);
me.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
return "邮件发送成功!~";
}
}