使用C#怎么群发邮件

要C#实现代码... 要C# 实现代码 展开
 我来答
百度网友0f37e23c0
2010-06-01 · TA获得超过1543个赞
知道大有可为答主
回答量:1070
采纳率:50%
帮助的人:1282万
展开全部
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;

using System.ComponentModel;
using System.Data;
using System.Threading;

namespace MailObj
{

public delegate void SendCompleted(string MailObj_ID);
public class MailObj
{
private SmtpClient Client;
private MailMessage Mail;
private Attachment Att;
public string ID;
public string fromMailDisplayName;
public event SendCompleted CallSendCompleted;
public MailObj(string ID)
{
this.ID = ID;
}
public MailObj(string ID, string fromMailDisplayName)
{
this.ID = ID;
this.fromMailDisplayName = fromMailDisplayName;
}
public bool CreateMail(string From, string To, string Subject, string Body, string FileName, string Smtp, string Uid, string Pwd, bool IsBodyHtml)
{
try
{
MailAddress f = null;
if ( this.fromMailDisplayName.Length > 0 )
f = new MailAddress(From, this.fromMailDisplayName);
else
f = new MailAddress(From);
MailAddress t = new MailAddress(To);
this.Mail = new MailMessage(f, t);
this.Mail.Subject = Subject;
this.Mail.Body = Body;
this.Mail.IsBodyHtml = IsBodyHtml;
if (FileName != "")
{
Att = new Attachment(FileName);
this.Mail.Attachments.Add(Att);
}
this.Client = new SmtpClient(Smtp);
this.Client.DeliveryMethod = SmtpDeliveryMethod.Network;
this.Client.Timeout = 10000;
this.Client.Credentials = new System.Net.NetworkCredential(Uid, Pwd);
}
catch
{
Dispose();
return false;
}
return true;
}
public void SendAsync()
{
//try
//{
if (this.Client != null && this.Mail != null)
{
Client.SendCompleted += new SendCompletedEventHandler(Client_SendCompleted);
Client.SendAsync(this.Mail, new object());
}
//}
//catch
//{
//}
//finally
//{
//}
}

private void Client_SendCompleted(object sender, AsyncCompletedEventArgs e)
{
if (this.CallSendCompleted != null && this.ID != "")
this.CallSendCompleted(this.ID);
}

public void Dispose()
{
this.Client = null;
if ( this.Mail != null )
this.Mail.Dispose();
}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式