62,046
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
string path = "d:\\";
string name = "李静";
string poptity = "1";
string sendEmail = "644591331@qq.com";
string sub = "sdzfsdfsdfsdfsdf";
string body = "dfsdfsdfsdfdsf";
string data = "pop.qq.com";
int num = 0;
ReciveMail("644591331", "密码", ref poptity, ref name, ref sendEmail, ref sub, ref body, ref path, ref data, out num, "d:\\");
}
/// <summary>
/// 利用JMAIl接收邮件
/// </summary>
/// <param name="mailname">油箱用户名称</param>
/// <param name="mailpwd">油箱密码</param>
/// <param name="poptity">等级</param>
/// <param name="senders">发送者</param>
/// <param name="sendmail">发件人地址</param>
/// <param name="subject">主题</param>
/// <param name="body">内容</param>
/// <param name="path">路径</param>
/// <param name="data">数据</param>
/// <param name="num1">输出参数</param>
public static void ReciveMail(string mailname, string mailpwd, ref string poptity, ref string senders, ref string sendmail, ref string subject, ref string body, ref string path, ref string data, out int num1, string paths)
{
num1 = 1;
jmail.POP3Class popMail = new jmail.POP3Class();
jmail.Message mailMessage;
jmail.Attachments atts;
jmail.Attachment att;
//string pop = "pop." + mailname.Substring(mailname.IndexOf("@") + 1);
string pop = "pop.qq.com";
//这个地方就报错 错误信息:This function is not included in this version of jmail.
popMail.Connect(mailname, mailpwd, pop, 110);
if (0 < popMail.Count)
{
for (int i = 1; i <= popMail.Count; i++)
{
mailMessage = popMail.Messages[i];
atts = mailMessage.Attachments;
mailMessage.Charset = "GB2312";
mailMessage.Encoding = "Base64";
mailMessage.ISOEncodeHeaders = false;
poptity = mailMessage.Priority.ToString();
senders = mailMessage.FromName;
sendmail = mailMessage.From;
subject = mailMessage.Subject;
body = mailMessage.Body;
data = mailMessage.Date.ToString();
string size = mailMessage.Size.ToString();
for (int j = 0; j < atts.Count; j++)
{
if (j == 0)
{
//取得附件名称
att = atts[j];
/**/
/**/
/**/
///附件名称
string attname = att.Name;
// int k = attname.LastIndexOf(".");
// string time = DateTime.Now.ToString();
// time = time.Replace("-","");
// time = time.Replace(" ","");
// time = time.Replace(":","");
// attname = attname.Insert(attname.LastIndexOf("."),"-"+time);
/**/
///上传到服务器
//path="D:\\Mail\\mailre\\"+attname;
string all = paths + "\\Mail\\MailReceive\\";
path = all + attname;
DirectoryInfo dir = new DirectoryInfo(all);
if (dir.Exists)
{
att.SaveToFile(path);
}
else
{
dir.Create();
att.SaveToFile(path);
}
}
}
popMail.DeleteSingleMessage(i);//删除邮件
}
att = null;
atts = null;
popMail.Disconnect();
popMail = null;
}
else
{
num1 = 0;
att = null;
atts = null;
popMail.Disconnect();
popMail = null;
}
}