询问者
模拟exchange在sharepoint server 2010发送邮件

问题
全部回复
-
Hi virus,
如果你是想通过开发来发送邮件,你只需要获取下面一exchage的一些字段(用户名,密码,邮件服务器的地址等等)就可以了 .下面是我曾经写的发送邮件的一个类。你可以比较一下。
public class Common
{
private string userName;
private string password;
private string mailServer;
private string sendMail;
private string ccMail;public Common()
{
userName = RSBLL.GetString("MailUser");//MailUser等都是配置在资源文件中,你可以先死。直接用字符串就行了。
password = RSBLL.GetString("MailPassword");
mailServer = RSBLL.GetString("MailServer");
sendMail = RSBLL.GetString("MailSender");
ccMail = RSBLL.GetString("MailCC");
}
/// <summary>
/// Public Send mail function
/// </summary>
/// <param name="receiveMail">Send address</param>
/// <param name="cc">cc addresss,can bu null</param>
/// <param name="subject">Subject</param>
/// <param name="body">Content</param>
/// <param name="attachmentsFilePath">Attachments</param>
public void SendMail(string receiveMail,string cc,string subject,string body,string[] attachmentsFilePath)
{
//object
SmtpClient client = new SmtpClient();
MailMessage message = new MailMessage();
try
{
//login to server
client.Credentials = new NetworkCredential(userName, password);
client.Host = mailServer;
//address
message.From = new MailAddress(sendMail);
message.To.Add(receiveMail);string mailCC = String.Join(",", new string[] { ccMail, cc });
string[] mailCCs = mailCC.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
Regex reg = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
foreach (string mail in mailCCs)
{
if(reg.IsMatch(mail) && mail.ToLower().Contains("cadence"))
{
message.CC.Add(mail);
}
}
//subject
message.Subject = subject;
//body
message.Body = body;
message.IsBodyHtml = false;
message.BodyEncoding = Encoding.UTF8;
//attachments
if (attachmentsFilePath != null)
{
foreach (string attFile in attachmentsFilePath)
{
message.Attachments.Add(new Attachment(attFile));
}
}
//send
client.Send(message);
}
catch (Exception ex){
throw ex;
}
finally{
//clear
message.To.Clear();
message.CC.Clear();
message.Attachments.Clear();
message.Subject = String.Empty;
message.Body = String.Empty;
}
}}
Thanks,
Jack
- 已编辑 Jack-GaoModerator 2012年1月17日 2:11
- 已标记为答案 virus black 2012年2月9日 4:08
- 取消答案标记 virus black 2012年11月1日 6:45