2017-11-17 111 views
1

注意:在發現Outlook版本是32位而不是64位之後,從原始編輯。使用自動化發送帶有32位Outlook的電子郵件時的地址錯誤

我有一個傳統的32位VB6程序,使用Outlook 2010 32位(完整版,不是快遞)發送電子郵件。除了一臺使用Windows 7的計算機(我認爲是64位)之外,許多計算機都可以正常工作。不知道是否所有的Windows 7機器不工作或只是這一個。

如果我使用自動化技術或MAPI技術(我稱之爲,請參閱下面的代碼)outlook發送電子郵件,但郵件服務器將其作爲無法傳送的郵件將其踢回,表示收件人不存在。

現在,如果使用自動化技術,outlook將不會顯示UI,並且電子郵件將在後臺發送。

但是,如果使用MAPI技術,outlook會打開它的撰寫電子郵件對話框,允許用戶在發送之前編輯電子郵件。有趣的是,收件人的電子郵件看起來很好,但如果發送則無法送達。但是,如果收件人被刪除並重新輸入,那麼電子郵件將成功。我相信一個副本,並重新粘貼作品也。

這告訴我,收件人電子郵件地址中必須有一個或多個隱藏的非法字符(空值也許?)。下面顯示的代碼非常簡單,我想不出任何明顯的修復方法。 txtTo是帶有電子郵件地址的vb6字符串,這是導致所有問題的字段。

錯誤消息:

Your message did not reach some or all of the intended recipients. 

    Subject: a test from daryls cpu #2 
    Sent: 11/17/2017 8:01 PM 

    The following recipient(s) cannot be reached: 

    '[email protected]' on 11/17/2017 8:01 PM 
     None of your e-mail accounts could send to this recipient. 

自動化技術

 Dim mOutlookApp As Object 
     Set mOutlookApp = GetObject("", "Outlook.application") 

     Dim olNs As Object 
     Set olNs = mOutlookApp.GetNamespace("MAPI") 
     olNs.Logon 

     Dim OutMail As Object 
     Set OutMail = mOutlookApp.CreateItem(0) 

     'Set the To and Subject lines. Send the message. 
     With OutMail 
      .To = txtTo 
      .CC = txtCC 
      .Subject = txtSubjext 
      .HTMLBody = txtBody & vbCrLf 

      Dim myAttachments As Object 
      Set myAttachments = .Attachments 
      vAttach = Split(mAttachments, ",") 
      For i = 0 To UBound(vAttach) 
       myAttachments.add vAttach(i) 
      Next i 


      Dim myFolder As Object 
      Set myFolder = olNs.GetDefaultFolder(5) 'olFolderSent 
      Set .SaveSentMessageFolder = myFolder 

      StatusBar1.Panels(1).Text = "Status: Sending" 

      .send 
     End With 

MAPI技術

'Open up a MAPI session: 
    With frmMain.MAPISession1 
     .DownLoadMail = False 
     .Username = "" 
     .LogonUI = True 
     .SignOn 
    End With 

    With frmMain.MAPIMessages1 
     .SessionID = frmMain.MAPISession1.SessionID 
     .Compose 
     .MsgIndex = -1 

     .RecipIndex = 0 
     .RecipAddress = txtTo 
     .RecipDisplayName = txtTo 
     .RecipType = mapToList 

     If txtCC <> "" Then 
      .RecipIndex = 1 
      .RecipDisplayName = txtCC 
      .RecipAddress = txtCC 
      .RecipType = mapCcList 
     End If 

     'spaces are important! need one space for each attachment 
     'NOTE .MsgNoteText = " " MUST be there see.. KB173853 in microsoft 

     .MsgSubject = txtSubjext 

     .MsgNoteText = Space$(UBound(vAttach) + 1) & vbCrLf 
     .MsgNoteText = txtBody & vbCrLf 

     For i = 0 To UBound(vAttach) 
      .AttachmentIndex = i 
      .AttachmentPosition = i 
      .AttachmentType = mapData 
      .AttachmentName = GetFileFromPath(vAttach(i)) 
      .AttachmentPathName = vAttach(i) 
     Next i 

     StatusBar1.Panels(1).Text = "Status: Sending" 

     .send True 

    End With 

更多信息:

我取得一些進展。該錯誤與Outlook中的電子郵件類型不是SMTP有關。如果在Outlook撰寫對話框中的發送郵件中右鍵單擊電子郵件地址,然後選擇Outlook屬性並將電子郵件類型更改爲SMTP,它將起作用。顯示的類型是電子郵件地址本身,有效值似乎是'mailto'和'smtp'。所以如果我可以從vb6設置電子郵件類型,它應該修復錯誤。

'答案'? https://kb.intermedia.net/article/2344

我不能相信沒有修復這個...

+0

如果你能總結出真正的問題是什麼,可能會幫助未來遇到這個問題的人 – DaveInCaz

回答

0

解決!

我知道這個話題是最有可能在20世紀沒有興趣編程的人,但這裏的修復:

.RecipAddress = "SMTP:" & txtTo 

它只是來找我。 :)

+0

相反,有足夠多的人認爲這可能有用! – DaveInCaz

相關問題