none
EWS 发送邮件失败提示 “The request failed. 操作超时" RRS feed

  • 问题

  • EWS添加的附件单个附件大小如果超过1.几M,发送时提示“The request failed. 操作超时”,如果单个附件不大,例如0.9M,添加多个附件发送都不会提示错误。

    c# 代码:

    	static void Main(string[] args)
            {
                try
                {
                    string username = args[0];
                    string password = args[1];
                    string domain = args[2];
                    string frommail = args[3];
                    string subject = args[4];
                    string body = args[5];
                    string[] tos = args[6].Split(';');
                    string[] files = args[7].Split(';');
    		
                    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                    
                    service.Credentials = new WebCredentials(username, password, domain);
                    service.TraceEnabled = true;
                    service.TraceFlags = TraceFlags.All;
                    service.AutodiscoverUrl(frommail, RedirectionUrlValidationCallback);
                    EmailMessage email = new EmailMessage(service);
                    
                    foreach (string t in tos)
                    {
                        email.ToRecipients.Add(t);
                    }
                    email.Subject = subject;
                    email.Body = new MessageBody(body);
                    foreach (string s in files)
                    {
                        email.Attachments.AddFileAttachment(s);
                    }
                    
                    email.Send();
                }
                catch (Exception ex)
                {
                    System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "\\Error.log", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ")+ex.Message+"\r\n");
                }
            }
    	private static bool RedirectionUrlValidationCallback(string redirectionUrl)
            {
                bool result = false;
                Uri redirectionUri = new Uri(redirectionUrl);
                if (redirectionUri.Scheme == "https")
                {
                    result = true;
                }
                return result;
            }


    dog

    2015年7月12日 12:57

答案