{求助}c#邮件发面的协议语法
学c#一年了 还没有做过网络发面的软件 求一个收发邮件的协议 --------------------编程问答--------------------界面做好了 就差这方面的协议,下午图书馆去查资料去了
大神些给点资料 --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.Net.Mail;
using System.IO;
using System.Net.Mime;
using System.Net;
namespace MailTo
{
class MailHelper
{
public string smtp;
public string from;
public string displayname;
public string pwd;
public string to;
public string subject;
public string body;
public ArrayList paths;
public bool blnUseSSL;
public MailHelper(string Psmtp, string Pfrom, string Ppwd, string Pdisplayname, string Pto, string Psubject, string Pbody, ArrayList Ppaths, bool PblnUseSSL)
{
smtp = Psmtp;
from = Pfrom;
displayname = Pdisplayname;
pwd = Ppwd;
to = Pto;
subject = Psubject;
body = Pbody;
paths = Ppaths;
blnUseSSL = PblnUseSSL;
}
public bool SendMail()
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(from, displayname, Encoding.UTF8);
mail.To.Add(to);
mail.Subject = subject;
mail.SubjectEncoding = Encoding.Default;
mail.Body = body;
mail.BodyEncoding = Encoding.Default;
mail.IsBodyHtml = false;
mail.Priority = MailPriority.Normal;
//添加附件
Attachment attachment = null;
if (paths.Count > 0)
{
for (int i = 0; i < paths.Count; i++)
{
string pathFileName = paths[i].ToString();
string extName = Path.GetExtension(pathFileName).ToLower();
//判断附件类型
if (extName == ".rar" || extName == ".zip")
{
attachment = new Attachment(pathFileName, MediaTypeNames.Application.Zip);
}
else
{
attachment = new Attachment(pathFileName, MediaTypeNames.Application.Octet);
}
ContentDisposition cd = attachment.ContentDisposition;
cd.CreationDate = File.GetCreationTime(pathFileName);
cd.ModificationDate = File.GetLastWriteTime(pathFileName);
cd.ReadDate = File.GetLastAccessTime(pathFileName);
mail.Attachments.Add(attachment);
}
}
SmtpClient client = new SmtpClient();
client.Host = smtp;
client.Port = 25;
//是否使用安全套接字层加密连接
client.EnableSsl = blnUseSSL;
//不使用默认凭证,注意此句必须放在 client.Credentials 的上面
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(from, pwd);
//邮件通过网络直接发送到服务器
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(mail);
return true;
}
catch
{
return false;
}
finally
{
mail.Dispose();
client = null;
}
}
}
}
--------------------编程问答-------------------- 这是发邮件的。可以参考下 --------------------编程问答-------------------- 收发邮件是标准协议,你不能自定义的,可以用.net自带的也可以用第三方的如,jmail
补充:.NET技术 , C#