据说Jmail是个好东西,所以就搞了一下午+一晚上,课愣是没搞定:
1.发邮件:
代码如下:
private jmail.Message jMessage = new jmail.MessageClass();
jMessage.Charset = "GB2312";
jMessage.Logging = true;
jMessage.AddRecipient(“[email protected]”, "", "");
jMessage.From = "[email protected]";
jMessage.FromName = "litonghui1990"
jMessage.Priority = 1;
jMessage.Subject = "sfd";
jMessage.Body = "sfjdkl";
jMessage.MailServerUserName = "litonghui1990";
jMessage.MailServerPassWord = "*******";
try
{
jMessage.Send("smtp.gmail.com", false);
MessageBox.Show("Succeeded!!");
}
catch(Exception exp)
{
MessageBox.Show("Failed!" + exp.Message);
} 结果抛出错误:Failed!!The message was undeveliverable.All servers failed to receive the message.
2.收邮件部分: 代码如下:
jmail.POP3 myPop3 = new jmail.POP3Class(); try
{
myPop3.Connect("litonghui1990", "*******", "pop3.gmail.com", 110);
myPop3.Logging = true;
}
catch (Exception exp)
{
MessageBox.Show("Failed while connecting the POP3serer:" + exp.Message);
return;
}
.................//后续代码 结果跑出了错误:Failed while connecting the POP3 server:WSAGetlasterror() returned 11004 no data perhaps no route to host.上网搜了很多,但没找到能解决的办法,哪位大侠帮忙解决一下呀~~~
1.发邮件:
代码如下:
private jmail.Message jMessage = new jmail.MessageClass();
jMessage.Charset = "GB2312";
jMessage.Logging = true;
jMessage.AddRecipient(“[email protected]”, "", "");
jMessage.From = "[email protected]";
jMessage.FromName = "litonghui1990"
jMessage.Priority = 1;
jMessage.Subject = "sfd";
jMessage.Body = "sfjdkl";
jMessage.MailServerUserName = "litonghui1990";
jMessage.MailServerPassWord = "*******";
try
{
jMessage.Send("smtp.gmail.com", false);
MessageBox.Show("Succeeded!!");
}
catch(Exception exp)
{
MessageBox.Show("Failed!" + exp.Message);
} 结果抛出错误:Failed!!The message was undeveliverable.All servers failed to receive the message.
2.收邮件部分: 代码如下:
jmail.POP3 myPop3 = new jmail.POP3Class(); try
{
myPop3.Connect("litonghui1990", "*******", "pop3.gmail.com", 110);
myPop3.Logging = true;
}
catch (Exception exp)
{
MessageBox.Show("Failed while connecting the POP3serer:" + exp.Message);
return;
}
.................//后续代码 结果跑出了错误:Failed while connecting the POP3 server:WSAGetlasterror() returned 11004 no data perhaps no route to host.上网搜了很多,但没找到能解决的办法,哪位大侠帮忙解决一下呀~~~
//可以用jmail组件发送邮件 也可以用.NET组件进行发送 前提:需要注册sina邮箱,开启smtp和pop3服务
/// 发送邮件
/// </summary>
/// <param name= "strSmtpServer "> smtp地址 </param>
/// <param name= "UserName "> 用户名 </param>
/// <param name= "Password "> 密码 </param>
/// <param name= "strFrom "> 发信人地址 </param>
/// <param name= "strto "> 收信人地址 </param>
/// <param name= "strSubject "> 邮件标题 </param>
/// <param name= "strBody "> 邮件正文 </param>
public static void SendMail(string strSmtpServer,string UserName,string Password,string strFrom, string strto,string strSubject,string strBody)
{
//生成一个 使用SMTP发送邮件的客户端对象
System.Net.Mail.SmtpClient client=new System.Net.Mail.SmtpClient(strSmtpServer);
//表示以当前登录用户的默认凭据进行身份验证
client.UseDefaultCredentials=true;
//包含用户名和密码
client.Credentials = new System.Net.NetworkCredential(UserName,Password);
//指定如何发送电子邮件。
//Network 电子邮件通过网络发送到 SMTP 服务器。
client.DeliveryMethod =System.Net.Mail.SmtpDeliveryMethod.Network;
//建立邮件对象
System.Net.Mail.MailMessage message =new System.Net.Mail.MailMessage(strFrom,strto,strSubject,strBody);
//定义邮件正文,主题的编码方式
message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312"); // 注意不要有空格,否则会出现错误:不支持编码方式
message.SubjectEncoding = System.Text.Encoding.GetEncoding( "GB2312");
//获取或设置一个值,该值指示电子邮件正文是否为 HTML。
message.IsBodyHtml=true ;
//发件人身份验证
client.Credentials = new System.Net.NetworkCredential(strFrom, Password);
//发送
client.Send(message);
} //调用函数
SendMail("smtp.sina.com.cn", "注册的用户名", "密码", "发件人地址", this.TBEmail.Text, "论坛系统激活信件,请勿回复!", "<html> <head> <title></tilet></head><body>恭喜您已经注册成功,请点击以下地址进行激活,若不能点击可将地址复制到浏览器地址栏中进行激活!<A href=www.bbs/active.aspx>www.bbs/active.aspx</A></body></html>");这是我以前做的 我用的.net的内置组件用的新浪的smtp服务器
首先你要注册个新浪的免费邮箱,然后进入邮箱在设置里面选择开启smtp和pop3服务就可以了
改成163以后还是错误:-ERR您没有权限使用POP3功能……
using System.Web.Mail;//添加引用 发送邮件
Imports System.Net.Mail.MailMessage
Imports System.Net.Mail.SmtpClient
改成 myPop3.Connect("litonghui1990", "*******", "pop.gmail.com", 995);后还是出错:Connection reset by client server.这是怎么回事儿呀??哪位高手做过这方面的研究没????