asp.net 2.0 如何发送电子邮件
asp.net 2.0 如何发送电子邮件?本人用了n多方法,都提示错误,请指教!多谢各位了!!
------解决方案--------------------system.web.mail 吧 记不太清了 这个是.net自带的
或者 可以用Jmail
------解决方案--------------------{
MailMessage mailMsg = new MailMessage(from,to);
mailMsg.IsBodyHtml = true;
mailMsg.Body = "asdfasdf <hr> ";
mailMsg.Subject = "ceshie ";
SmtpClient client = new SmtpClient( "smtp.126.com ");//smpt服务器
client.Credentials = new NetworkCredential( "用户名 ", "密码 ");
client.Send(mailMsg);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
------解决方案--------------------JMAIL实现我有源码
我给你
经过测试没问题可以多发!
1.安装jmail4.3
2.找到jmail.dll(Program Files\Dimac\w3JMail4下)
3.执行Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin\ildasm.exe(可使用Visual Studio .Net 2003 命令提示),
格式如下:tlbimp c:\Program Files\Dimac\w3JMail4\jmail.dll /out:myJmail.dll /namespace:myJmail
就是我在Visual Studio .Net 2005命令提示下编译执行 tlbimp c:\Program Files\Dimac\w3JMail4\jmail.dll /out:myJmail.dll /namespace:myJmail
using System;
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.Web.Mail;
using System.Web.Util;
using myJmail;
using Tool;
using Manager;
using Entity;
public partial class UserControls_Jmaill : System.Web.UI.UserControl
{
string strCurrentPath = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
this.lblTitle.Text = "发送邮件控件 ";
myJmail.Message Jmail = new myJmail.Message();
DateTime t = DateTime.Now;
String Subject = this.txtTitle.Text;
String body = this.txtContent.Text;
string FromEmail = this.txtFormEmail.Text.Trim();//你的email
String ToEmail = this.txtToEmail.Text;//对方的email
String AddAttachment = this.FileUploadSubject.PostedFile.FileName;
//Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
Jmail.Silent = true;
//Jmail创建的日志,前提loging属性设置为true
Jmail.Logging = true;
//字符集,缺省为 "US-ASCII "
Jmail.Charset = "GB2312 ";
//信件的contentype. 缺省是 "text/plain ") : 字符串如果你以HTML格式发送邮件, 改为 "text/html "即可。
// Jmail.ContentType = "text/html ";
ToEmail = ToEmail.Replace( "\n ", " ").Replace( " ", " ");
string[] str = ToEmail.Split( ', ');
for (int i = 0; i < str.Length; i++)
{
//添加收件人
Jmail.AddRecipient(str[i], " ", " ");
Jmail.From = FromEmail;
//发件人邮件用户名
Jmail.MailServerUserName = FromEmail;
//发件人邮件密码