asp.net 接收邮件 有个想法用asp.net做个接收邮件功能比如雅虎,新浪,163 等等网站上的邮件同时接收还有想获得,联系人列表例如:OutLook上的通讯簿列表请高手指教!!!!!!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 MsnHelper msn = new MsnHelper(); msn.Start("MSN帐号", "MSN密码"); List<MsnFriend> list = msn.getFriends(); //获取好友 MailInfo m = new MailInfo(); m.UserName = "[email protected]"; //发件人帐号 m.Password = "123123"; //邮箱密码 m.Smtp = "smtp.gmail.com"; //smtp服务器 m.Port = 587; //smtp服务器服务端口 m.Ssl = true; //是否ssl加密 m.Title = "邮件标题"; m.Body = "<h1>邮件内容<h1>"; //获取好友emial foreach (MsnFriend msnf in list) { m.AddTo(msnf.Email); } m.IsBodyHtml = true; //内容解析html SendMail send = new SendMail(m); send.Send(); MsnHelper 是什么类啊上哪里引啊?????? private static void sendMail(string email, string password) { string smtpServer = "smtp.gmail.com";//服务器 int smtpPort = 587;//端口 string userAccount = "";//用户名 string userPassword = "";//密码 string userName = "";//发件人名称 string EmailAddress = "";//发件邮箱 string strto = email;//目的邮箱 string strSubject = "";//主题 string strBody = "";//内容 System.Net.Mail.SmtpClient client = new SmtpClient(smtpServer, smtpPort); client.EnableSsl = true; client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential(userAccount, userPassword); client.DeliveryMethod = SmtpDeliveryMethod.Network; MailAddress fromEmal = new MailAddress(EmailAddress, userName); MailAddress toEmail = new MailAddress(strto); System.Net.Mail.MailMessage message = new MailMessage(fromEmal, toEmail); message.Subject = strSubject; message.Body = strBody; message.BodyEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; client.Send(message); }这个吧。using System.Net.Mail;using System.Net; //我测试的时候用的是163的邮箱,163的免费POP邮件服务器是pop.163.com。而163官方给出的是 //pop.126.com在这里不能用,原因是这个邮件服务器是有SSL加密的,GMAIL我也测试了也不能用都是这个原因using System;using System.Text;using System.IO;using Email.POP3;namespace TestPOP3{ class example { [STAThread] static void Main(string[] args) { POP3 objPOP3 = new POP3("pop.163.com", 110, "用户名", "密码"); Console.WriteLine(objPOP3.Connect() ? "Connected" : "Can't connect"); try { if (objPOP3.IsAPOPSupported) { Console.WriteLine(objPOP3.SecureLogin() ? "Secure Logged in" : "Can't login"); } else { Console.WriteLine(objPOP3.Login() ? "Logged in" : "Can't login"); } objPOP3.QueryServer(); Console.WriteLine("Emails count: " + objPOP3.TotalMailCount); //以下的FOR循环是显示出所有收件箱里面的邮件信息 for (int i = 1; i <= objPOP3.TotalMailCount; i++) { EmailMessage objEmail = objPOP3.GetMessage(i, false); // use true to get headers only Console.WriteLine("NEW MESSAGE:------------------"); Console.WriteLine("FROM: " + objEmail.From); Console.WriteLine("TO: " + objEmail.To); Console.WriteLine("CC: " + objEmail.Cc); Console.WriteLine("SUBJECT: " + objEmail.Subject); Console.WriteLine("DATE: " + objEmail.Date); Console.WriteLine("CONTENT-TYPE: " + objEmail.ContentType); Console.WriteLine("CHARSET: " + objEmail.Charset); Console.WriteLine("MESSAGE-ID: " + objEmail.GetCustomHeader("Message-ID")); Console.WriteLine("MESSAGE SIZE: " + objEmail.Size); if (objEmail.IsAnyAttachments) { for (int a = 0; a < objEmail.Attachments.Count; a++) { //调用邮件附件的方法 processAttachment((Attachment)objEmail.Attachments[a], 1); } } else { Console.WriteLine("BODY: " + Encoding.Default.GetString(Convert.FromBase64String(objEmail.Body))); } //下面注册掉的代码是删除该邮件 //objPOP3.DeleteMessage(i); } objPOP3.Close(); } catch (System.Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); objPOP3.Close(); return; } } static void processAttachment(Attachment att, int nesting) { for(int i = 0; i < nesting * 2; i++) Console.Write("-"); //以下注释掉的代码可以打开,以下都是关于邮件附件的相关信息,因为我只需要得到附件的文件信息^_^ //Console.WriteLine("ATT: "); //Console.WriteLine("ContentTransferEncoding: " + att.ContentTransferEncoding); //Console.WriteLine("ContentType: " + att.ContentType); //Console.WriteLine("EstimatedSize: " + att.EstimatedSize); //Console.WriteLine("FileName: " + att.FileName); //processBody("HtmlBody", att.HtmlBody); //processBody("TextBody", att.TextBody); //Console.WriteLine("IsAnyAttachments: " + att.IsAnyAttachments); //Console.WriteLine("IsFileAttachment: " + att.IsFileAttachment); if (att.IsAnyAttachments) { for (int a = 0; a < att.Attachments.Count; a++) { processAttachment((Attachment)att.Attachments[a], nesting * 2); } } if(att.IsFileAttachment) { //这里说一下在保存邮件附件之前必须"c:\pop3"该文件夹是存在的,否则是保存不了的 att.Save(@"c:\pop3" + att.FileName); Console.WriteLine("附件保存成功!附件名称为:" + att.FileName); } } static void processBody(string bodytype, string body) { if (body == null) { Console.WriteLine(bodytype + ": null"); return; } if (body.Length > 1000) { Console.WriteLine(bodytype + ": " + body.Substring(0, 1000) + "..."); } else { Console.WriteLine(bodytype + ": " + body); } } }} Email.POP3;这个去哪里找啊 Datagrid中的一列显示状态,怎么实现这个状态的改变?内详,谢谢帮助 简单问题寻求答案. js日历控件 急用:Dll调用问题 急用急用急用 紧急求援,数据被删除,求高手赐教! datagird 删除问题 求助! 求助 连接sql数据库出错 【求教】用模板引擎生成的邮件内容问题 发现“csdn”有个错误,版主给我点奖励吧 做.net的暂无工作或想跳槽得朋友,看看这个 最近开发一个网站需要用到DataGrid1里的单选按钮。。。 讨论一下代码和UI的分离
msn.Start("MSN帐号", "MSN密码");
List<MsnFriend> list = msn.getFriends(); //获取好友
MailInfo m = new MailInfo();
m.UserName = "[email protected]"; //发件人帐号
m.Password = "123123"; //邮箱密码
m.Smtp = "smtp.gmail.com"; //smtp服务器
m.Port = 587; //smtp服务器服务端口
m.Ssl = true; //是否ssl加密
m.Title = "邮件标题";
m.Body = "<h1>邮件内容<h1>";
//获取好友emial
foreach (MsnFriend msnf in list)
{
m.AddTo(msnf.Email);
}
m.IsBodyHtml = true; //内容解析html
SendMail send = new SendMail(m);
send.Send();
{
string smtpServer = "smtp.gmail.com";//服务器
int smtpPort = 587;//端口
string userAccount = "";//用户名
string userPassword = "";//密码
string userName = "";//发件人名称
string EmailAddress = "";//发件邮箱
string strto = email;//目的邮箱
string strSubject = "";//主题
string strBody = "";//内容 System.Net.Mail.SmtpClient client = new SmtpClient(smtpServer, smtpPort);
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(userAccount, userPassword);
client.DeliveryMethod = SmtpDeliveryMethod.Network; MailAddress fromEmal = new MailAddress(EmailAddress, userName);
MailAddress toEmail = new MailAddress(strto);
System.Net.Mail.MailMessage message = new MailMessage(fromEmal, toEmail);
message.Subject = strSubject;
message.Body = strBody;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true; client.Send(message);
}
这个吧。
using System.Net.Mail;
using System.Net;
//pop.126.com在这里不能用,原因是这个邮件服务器是有SSL加密的,GMAIL我也测试了也不能用都是这个原因
using System;
using System.Text;
using System.IO;
using Email.POP3;
namespace TestPOP3
{
class example
{
[STAThread]
static void Main(string[] args)
{
POP3 objPOP3 = new POP3("pop.163.com", 110, "用户名", "密码");
Console.WriteLine(objPOP3.Connect() ? "Connected" : "Can't connect");
try
{
if (objPOP3.IsAPOPSupported)
{
Console.WriteLine(objPOP3.SecureLogin() ? "Secure Logged in" : "Can't login");
}
else
{
Console.WriteLine(objPOP3.Login() ? "Logged in" : "Can't login");
}
objPOP3.QueryServer();
Console.WriteLine("Emails count: " + objPOP3.TotalMailCount);
//以下的FOR循环是显示出所有收件箱里面的邮件信息
for (int i = 1; i <= objPOP3.TotalMailCount; i++)
{
EmailMessage objEmail = objPOP3.GetMessage(i, false); // use true to get headers only
Console.WriteLine("NEW MESSAGE:------------------");
Console.WriteLine("FROM: " + objEmail.From);
Console.WriteLine("TO: " + objEmail.To);
Console.WriteLine("CC: " + objEmail.Cc);
Console.WriteLine("SUBJECT: " + objEmail.Subject);
Console.WriteLine("DATE: " + objEmail.Date);
Console.WriteLine("CONTENT-TYPE: " + objEmail.ContentType);
Console.WriteLine("CHARSET: " + objEmail.Charset);
Console.WriteLine("MESSAGE-ID: " + objEmail.GetCustomHeader("Message-ID"));
Console.WriteLine("MESSAGE SIZE: " + objEmail.Size);
if (objEmail.IsAnyAttachments)
{
for (int a = 0; a < objEmail.Attachments.Count; a++)
{
//调用邮件附件的方法
processAttachment((Attachment)objEmail.Attachments[a], 1);
}
}
else
{
Console.WriteLine("BODY: " + Encoding.Default.GetString(Convert.FromBase64String(objEmail.Body)));
}
//下面注册掉的代码是删除该邮件
//objPOP3.DeleteMessage(i); }
objPOP3.Close();
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
objPOP3.Close();
return;
} } static void processAttachment(Attachment att, int nesting)
{
for(int i = 0; i < nesting * 2; i++) Console.Write("-"); //以下注释掉的代码可以打开,以下都是关于邮件附件的相关信息,因为我只需要得到附件的文件信息^_^ //Console.WriteLine("ATT: ");
//Console.WriteLine("ContentTransferEncoding: " + att.ContentTransferEncoding);
//Console.WriteLine("ContentType: " + att.ContentType);
//Console.WriteLine("EstimatedSize: " + att.EstimatedSize);
//Console.WriteLine("FileName: " + att.FileName);
//processBody("HtmlBody", att.HtmlBody);
//processBody("TextBody", att.TextBody);
//Console.WriteLine("IsAnyAttachments: " + att.IsAnyAttachments);
//Console.WriteLine("IsFileAttachment: " + att.IsFileAttachment);
if (att.IsAnyAttachments)
{
for (int a = 0; a < att.Attachments.Count; a++)
{
processAttachment((Attachment)att.Attachments[a], nesting * 2);
}
}
if(att.IsFileAttachment)
{
//这里说一下在保存邮件附件之前必须"c:\pop3"该文件夹是存在的,否则是保存不了的
att.Save(@"c:\pop3" + att.FileName);
Console.WriteLine("附件保存成功!附件名称为:" + att.FileName);
}
} static void processBody(string bodytype, string body)
{
if (body == null)
{
Console.WriteLine(bodytype + ": null");
return;
}
if (body.Length > 1000)
{
Console.WriteLine(bodytype + ": " + body.Substring(0, 1000) + "...");
}
else
{
Console.WriteLine(bodytype + ": " + body);
}
}
}
}
这个去哪里找啊