2. 开始试验时并并不成功,原因是使用了 cy163@sina.com.cn 服务器。但新浪的邮件服务器似乎拒绝让JMail使用。
现在的邮件发送大多数需要STMP的身份验证,
.NET里面的
System.Web.Util
System.Web.Mail
就不可以了.
我写这篇文章是希望对大家开发项目有所帮助,高手见笑了
先要去找一个组件,名字叫 JMail
大家可以去网上找一下,下载下来安装上.
将jmail.dll引用到工程中
图1:
private void Button1_Click(object sender, System.EventArgs e)
{
jmail.Message Jmail=new jmail.Message();
DateTime t=DateTime.Now;
String Subject=" From EMail .net";
String body="你好科学12:15";
String FromEmail="ljt21@163.com";
String ToEmail="xiao-maolover@163.com";
//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";
//添加收件人
Jmail.AddRecipient(ToEmail,"","");
Jmail.From=FromEmail;
//发件人邮件用户名
Jmail.MailServerUserName="ljt21" ;
//发件人邮件密码
Jmail.MailServerPassWord="****" ;
//设置邮件标题
Jmail.Subject=Subject;
//邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
Jmail.AddAttachment( "c:\\test.jpg",true,null);
//邮件内容
Jmail.Body=body+t.ToString();
//Jmail发送的方法
Jmail.Send("smtp.163.com",false);
Jmail.Close() ;
}
这样就OK了..!
经过测试的,没有问题.
Feedback
# re: asp.net中使用JMail发邮件 回复
2004-05-20 13:19 by unruledboyMailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
mail.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here
SmtpMail.SmtpServer = "mail.mycompany.com"; //your real server goes here
SmtpMail.Send( mail );
The message was undeliverable. All servers failed to receive the message
.execute()
{
Trying server mail:smtp.163.com
smtp.163.com failed with the message: "WSAGetLastError() returned 11001, Host not found"
No socket for server. ConnectToServer()
1 of 1 servers failed
}
# re: asp.net中使用JMail发邮件 回复
2005-01-20 17:40 by tranvutan@hotmail.com另外,是否Jmail 必须安装后才能使用。而简单将jmail.dll拷贝只project的bin目录,再通过ADD Reference引用到project中是不工作的。
“The message was undeliverable. All servers failed to receive the message ”
这样的错误,不知道什么回事
The message was undeliverable. All servers failed to receive the message
.execute()
{
Trying server mail:kgish.com
kgish.com failed with the message: "Connection timed out"
No socket for server. ConnectToServer()
1 of 1 servers failed
}
如果邮件带有图片 往往发送不出去 这该怎么解决!!~!!!??!!!!!!
发件人的地址为:77777@163.com
SMTPServer="smtp.163.com" 'SMTP服务器,可以直接输入SMTP的IP地址或者网址
MailUser="77777@163.com" '代发送邮件的帐号,如果是不含@的帐号,就不能写@
SenderPassword="111111"
注:发件人地址与MailUser要相同,你试试看,这样能发不