首页新闻找找看学习计划

Exchange 邮箱服务器某些账号发送邮件总是被自动锁住,导致无法发送成功

0
悬赏园豆:20 [待解决问题]

是用C#开发的邮件发送功能总是出现如下错误“The request failed. 远程服务器返回错误: (401) 未经授权”
代码如下:

 1 public class ExchangeEmail
 2     {
 3         public ExchangeService service;
 4         public ExchangeEmail()
 5         {
 6             service = new ExchangeService(ExchangeVersion.Exchange2010);
 7             service.Credentials = new WebCredentials("mailAddress", "PWD", "Domain");
 8             service.Url = new Uri("https://domain/ews/exchange.asmx");
 9             service.TraceEnabled = true;
10             service.TraceFlags = TraceFlags.All;
11 
12         }
13         Logger log = new Logger();
14         public bool SendEmail(string SendTo, string EmailSubject, string EmailBody, string CCTo = "", string AttachmentName = "", byte[] AttachStream = null)
15         {
16             EmailMessage email = new EmailMessage(service);
17             try
18             {
19                 if (SendTo.IndexOf(";") > 0)
20                 {
21                     string[] EmailArray = SendTo.Split(';');
22                     foreach (string item in EmailArray)
23                     {
24                         email.ToRecipients.Add(item.TrimEnd().TrimStart());
25                     }
26                 }
27                 else
28                 {
29                     email.ToRecipients.Add(SendTo.TrimEnd().TrimStart());
30                 }
31                 if (CCTo != "")
32                 {
33                     if (CCTo.IndexOf(";") > 0)
34                     {
35                         string[] EmailArray = CCTo.Split(';');
36                         foreach (string item in EmailArray)
37                         {
38                             email.ToRecipients.Add(item.TrimEnd().TrimStart());
39                         }
40                     }
41                     else
42                     {
43                         email.CcRecipients.Add(CCTo.TrimEnd().TrimStart());
44                     }
45                     log.Log("Add CC Recipient " + CCTo + "  Successfully");
46                 }
47                 if (AttachmentName != "" && AttachStream != null)
48                 {
49                     email.Attachments.AddFileAttachment(AttachmentName, AttachStream);
50                 }
51                 email.Subject = EmailSubject;
52                 email.Body = new MessageBody(EmailBody);
53                 email.Body.BodyType = BodyType.HTML;
54                 email.Send();
55                 return true;
56             }
57             catch (Exception)
58             {
59                 return false;
60             }
61             finally
62             {
63                 email.ToRecipients.Clear();
64                 email.CcRecipients.Clear();
65                 email.BccRecipients.Clear();
66             }
67         }
68     }

当执行完方法之后 再进入服务器上查看对应的账号状态会发现状态如下图:

 

正常情况下 状态如下:

谁知道这是什么原因造成的??请大神给予指导,谢谢。

FallenPuppet的主页 FallenPuppet | 初学一级 | 园豆:182
提问于:2016-07-06 16:07
< >
分享
所有回答(1)
0

很明显,没有授权

流编程风 | 园豆:151 (初学一级) | 2016-07-08 09:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册