使用自动化发送带有32位Outlook的电子邮件时的地址错误

问题描述:

注意:在发现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

解决!

我知道这个话题是最有可能在20世纪没有兴趣编程的人,但这里的修复:

.RecipAddress = "SMTP:" & txtTo 

它只是来找我。 :)

+0

相反,有足够多的人认为这可能有用! – DaveInCaz