2011-11-24 39 views
0

任何人在這裏有使用Exchange Web服務的經驗。郵寄通過交換web服務(VB.NET)

我正在嘗試使用webservice向自己發送電子郵件。此電子郵件有另一個地址作爲發件人,但它一直以我的收件人的電子郵件地址作爲發件人,而不是:■

這是我的代碼:

Dim Message As MessageType = New MessageType() 
    Message.Subject = txt 
    Message.Body = New BodyType() 
    Message.Body.Value = ActiesOverzicht 

    Message.Sender = New SingleRecipientType 
    Message.Sender.Item = New EmailAddressType 
    Message.Sender.Item.EmailAddress = SenderEmail 

    Message.ToRecipients = New EmailAddressType(0) {} 
    Message.ToRecipients(0) = New EmailAddressType() 
    Message.ToRecipients(0).EmailAddress = RecipientsEmail 

    Message.Sensitivity = SensitivityChoicesType.Normal 

此消息進入一個列表中,併發送與下面的代碼:

Public Sub SendMailToOperator(messageList As List(Of MessageType), esb As ExchangeServiceBinding) 
    ' Create the CreateItem request. 
    Dim createEmailRequest As New CreateItemType() 

    ' Specifiy how the e-mail will be handled. 
    createEmailRequest.MessageDisposition = MessageDispositionType.SendOnly 
    createEmailRequest.MessageDispositionSpecified = True 

    ' Create the array of items. 
    createEmailRequest.Items = New NonEmptyArrayOfAllItemsType() 
    ' Add the message to the array of items to be created. 
    createEmailRequest.Items.Items = messageList.ToArray() 
    'createEmailRequest.Items.Items(0) = Message 

     ' Send a CreateItem request and get the CreateItem 
     ' response. 
     Dim createItemResponse As CreateItemResponseType = esb.CreateItem(createEmailRequest) 
    End Sub 

有沒有人有任何想法如何解決這個問題?或者是什麼導致它?

+0

在這種情況下,你的收件人是你自己?交流可能會挑起這一點。 –

回答

1

AFAIK交易所通常會發送者總是設置爲人的登錄。

身份有解決此幾種方法,最簡單的一種是不使用Exchange。只需發送郵件槽'普通'SMTP。

如果您必須使用Exchange,您應該以您嘗試使用的發件人的身份登錄,或者設置您嘗試用作發件人的帳戶的權限。您使用的發件人應該允許您用於登錄的帳戶代表它發送郵件。權限可以通過Outlook進行更改。

也可能有辦法在Exchange服務器上放寬此限制,但我不是Exchange管理員,所以我不知道如何。

+0

oooh k,所以當我讓我的代碼在一個服務中運行時,該服務運行在一個不同的標識上,而不是使用該標識?如果是這樣的話:我不介意這樣做。 – Zarkos

+0

在Active Directory環境中,它將使用該標識,我猜這對於服務仍然是正確的,但是您將不得不對此進行測試。否則,您可能會在連接到Exchange時顯式指定登錄,但我不知道如何在VB中執行此操作。 – AVee