您的位置:首页 > 其它

Windows Server 2008 R2 相关配置(一):邮件服务器(转)

2012-06-07 12:29 295 查看

Windows Server 2008 R2 相关配置(一):邮件服务器

Posted on 2012-03-24 17:15
lucio 阅读(228) 评论(0)
编辑 收藏


最近一年,一直在和一个澳大利亚的客户做金融相关的项目,由于客户那边没有专门的IT相关的开发和维护人员,所有的沟通都是基于Email和skype的方式,邮件系统是他们平时最为依赖的一部分,只要这部分出问题了,再多的其他正在进行的事情都要搁置起来,先解决这个,所以将这个放在第一部分:

Step1:在IIS7.5下启用IIS6的SMTP,见下图:



Step2:点击SMTP-->Propertites:



Step3:设置邮件IP地址:



Step4:这一步比较重要,设置Relay restriction开始就是没设置这一步导致浪费了一天时间:



在弹出的页面选择All except the list below:



Step5:设置允许的最大邮件大小,每天最大连接数:



Step6: 设置邮件发送失败重发的邮件频率等等:



OK,这样在相关的设置就完成了。

相关的C#的SMTP操作的代码如下:

1) 发送不带附件的邮件

1 /// <summary>

2 /// Send email without attachments

3 /// </summary>

4 /// <param name="ToMail">收件人邮箱地址</param>

5 /// <param name="FromMail">发件人邮箱地址</param>

6 /// <param name="Cc">抄送</param>

7 /// <param name="Bcc">密送</param>

8 /// <param name="Body">邮件正文</param>

9 /// <param name="Subject">邮件标题</param>

10 /// <returns></returns>

11 public string SendMail(string ToMail, string FromMail, string Cc, string Bcc, string Body, string Subject)

12 {

13 SmtpClient client = new SmtpClient();

14 MailMessage message = new MailMessage {

15 From = new MailAddress(FromMail)

16 };

17 message.To.Add(ToMail);

18 if (Cc != "")

19 {

20 message.CC.Add(Cc);

21 }

22 message.Body = Body;

23 message.Subject = Subject;

24 message.IsBodyHtml = true;

25 client.UseDefaultCredentials = true;

26 message.Priority = MailPriority.High;

27 client.Host = "127.0.0.1";//此处应该改为上面设置的服务器IP地址

28 client.Port = 0x19;

29 try

30 {

31 client.DeliveryMethod = SmtpDeliveryMethod.Network;

32 client.Send(message);

33 message.Dispose();

34 return "1";

35 }

36 catch (Exception exception)

37 {

38 return ("0" + exception);

39 }

40 }

2)发送带附件的邮件

2 /// Send email without attachments

3 /// </summary>

4 /// <param name="ToMail">收件人邮箱地址</param>

5 /// <param name="FromMail">发件人邮箱地址</param>

6 /// <param name="Cc">抄送</param>

7 /// <param name="Bcc">密送</param>

8 /// <param name="Body">邮件正文</param>

9 /// <param name="Subject">邮件标题</param>

10 /// <param name="Attachments">附件列表</param>

11 /// <returns></returns>

12 public string SendMailWithAttachment(string ToMail, string FromMail, string Cc, string Bcc, string Body, string Subject, string[] Attachments)

13 {

14 SmtpClient client = new SmtpClient();

15 MailMessage message = new MailMessage {

16 From = new MailAddress(FromMail)

17 };

18 message.To.Add(ToMail);

19 if (Cc != "")

20 {

21 message.CC.Add(Cc);

22 }

23

24 message.Body = Body;

25 message.Subject = Subject;

26 message.IsBodyHtml = true;

27 message.Priority = MailPriority.High;

28 if (Attachments.Length > 0)

29 {

30 for (int i = 0; i < Attachments.Length; i++)

31 {

32 if (Attachments[i].ToString() != "")

33 {

34 Attachment item = new Attachment(Attachments[i].ToString());

35 message.Attachments.Add(item);

36 }

37 }

38 }

39 client.Host = "127.0.0.1";//此处应该改为上面设置的服务器IP地址

40 client.Port = 0x19;

41 try

42 {

43 client.DeliveryMethod = SmtpDeliveryMethod.Network;

44 client.Send(message);

45 message.Dispose();

46 return "1";

47 }

48 catch (Exception exception)

49 {

50 return ("0" + exception);

51 }

52 }

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: