2016-10-05 155 views
0

我的问题是我似乎无法延迟发送该项目(已尝试2分钟到2天,没有运气)。使用Exchange Web服务(EWS)管理API延迟发送邮件

邮件本身立即发送,没有失败 - 这只是延迟不起作用?任何帮助,将不胜感激。

注 -

  • 我一直在使用this as an example大多数我的代码。

  • 我使用的Exchange 2010 SP2

  • 邮件发送很好,只是没有延迟


Public Class Mail 
    Private Const DEFERREDSENDTIMEFLAG As Integer = 16367 
    Public Shared ReadOnly Property EXCHANGESERVICEURL As String 
     Get 
      Return ConfigurationManager.AppSettings("EXCHANGESERVICEURL") 
     End Get 
    End Property 
    Public Shared ReadOnly Property DOMAINNAME As String 
     Get 
      Return ConfigurationManager.AppSettings("DOMAINNAME") 
     End Get 
    End Property 
    Public Shared ReadOnly Property EXCHANGEUSERNAME As String 
     Get 
      Return ConfigurationManager.AppSettings("EXCHANGEUSERNAME") 
     End Get 
    End Property 
    Public Shared ReadOnly Property EXCHANGEPASSWORD As String 
     Get 
      Return ConfigurationManager.AppSettings("EXCHANGEPASSWORD") 
     End Get 
    End Property 
    Public Shared ReadOnly Property EXCHANGEVERSION As ExchangeVersion 
     Get 
      Return CType(System.Enum.Parse(GetType(ExchangeVersion), ConfigurationManager.AppSettings("EXCHANGEVERSION")), ExchangeVersion) 
     End Get 
    End Property 
    Public Shared Sub SendMessage(ByVal fromAddress As String, ByVal toAddress() As String, ByVal ccAddress() As String, ByVal bccAddress() As String, ByVal subject As String, ByVal body As String, ByVal minutesDelay As Integer) 

     ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate) 
     Dim service As New ExchangeService(EXCHANGEVERSION) 
     service.Credentials = New WebCredentials(EXCHANGEUSERNAME, EXCHANGEPASSWORD, DOMAINNAME) 
     service.Url = New Uri(EXCHANGESERVICEURL) 

     Dim Message As New Microsoft.Exchange.WebServices.Data.EmailMessage(service) 
     'set delay send time 
     If minutesDelay > 0 Then 
      Dim sendTime As String = DateTime.Now.AddMinutes(minutesDelay).ToUniversalTime().ToString() 
      Dim PR_DEFERRED_SEND_TIME As New ExtendedPropertyDefinition(DEFERREDSENDTIMEFLAG, MapiPropertyType.SystemTime) 
      Message.SetExtendedProperty(PR_DEFERRED_SEND_TIME, sendTime) 
     End If 
     Message.From = fromAddress 
     If toAddress IsNot Nothing Then 
      For Each t As String In toAddress 
       Message.ToRecipients.Add(t) 
      Next 
     End If 
     If ccAddress IsNot Nothing Then 
      For Each t As String In ccAddress 
       Message.CcRecipients.Add(t) 
      Next 
     End If 
     If bccAddress IsNot Nothing Then 
      For Each t As String In bccAddress 
       Message.BccRecipients.Add(t) 
      Next 
     End If 
     Message.Subject = subject 
     Message.Body = body 


     Message.SendAndSaveCopy() 'save means make sure it's saved in the sent items folder 
     'message.Attachments 
    End Sub 

    Private Shared Function ValidateCertificate(sender As Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As SslPolicyErrors) As Boolean 
     Return True 
    End Function 
End Class 

回答

1

我建议你使用的类型变量而不是转换日期时间到一个字符串(就像例子那样)然后发送它。如只使用

Message.SetExtendedProperty(PR_DEFERRED_SEND_TIME, DateTime.Now.AddMinutes(minutesDelay).ToUniversalTime()) 

该库是专门用来对付类型变量,但你可以使用一个String VS类型的变量,如果你启用跟踪如

 <t:ExtendedProperty> 
      <t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime"/> 
      <t:Value>2016-05-10T03:20:16.000</t:Value> 
     </t:ExtendedProperty> 

VS

看到POST的区别
  <t:ExtendedProperty> 
      <t:ExtendedFieldURI PropertyTag="16367" PropertyType="SystemTime"/> 
      <t:Value>2016-10-05T03:12:30.067Z</t:Value> 
     </t:ExtendedProperty> 

您也可以修复字符串,但使用类型变量更有意义,您的示例运行良好。

+0

你是一个冠军,欢呼,工作就像一个魅力 –

相关问题