Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用automation以32位outlook发送电子邮件时的地址错误_Outlook_Vb6_Mapi - Fatal编程技术网

使用automation以32位outlook发送电子邮件时的地址错误

使用automation以32位outlook发送电子邮件时的地址错误,outlook,vb6,mapi,Outlook,Vb6,Mapi,注意:在我发现outlook版本是32位而不是64位之后,从原始版本进行了编辑 我有一个传统的32位VB6程序,它使用outlook 2010 32位(完整版,非express)发送电子邮件。除了一台装有Windows7(我想是64位)的机器外,它在许多机器上都能完美工作。不确定是所有windows 7机器都不能工作,还是只有这台 如果我使用自动化技术或MAPI技术(我称之为自动化技术或MAPI技术,请参见下面的代码),outlook会发送电子邮件,但邮件服务器会将其视为无法发送,并说收件人不存

注意:在我发现outlook版本是32位而不是64位之后,从原始版本进行了编辑

我有一个传统的32位VB6程序,它使用outlook 2010 32位(完整版,非express)发送电子邮件。除了一台装有Windows7(我想是64位)的机器外,它在许多机器上都能完美工作。不确定是所有windows 7机器都不能工作,还是只有这台

如果我使用自动化技术或MAPI技术(我称之为自动化技术或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:

  'someemail@gmail.com' 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
    '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
MAPI技术

        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
    '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
'打开MAPI会话:
使用frmMain.MAPISession1
.DownLoadMail=False
.Username=“”
.LogonUI=True
.签名
以
使用frmMain.MAPIMessages1
.SessionID=frmMain.MAPISession1.SessionID
组成
.MsgIndex=-1
.index=0
.RecipAddress=txtTo
.RecipDisplayName=txtTo
.RecipType=mapToList
如果txtCC“”则
.index=1
.RecipDisplayName=txtCC
.RecipAddress=txtCC
.RecipType=mapCcList
如果结束
“空间很重要!每个附件需要一个空间
'NOTE.MsgNoteText=”“必须在那里,请参见。。微软的KB173853
.MsgSubject=txtsubext
.MsgNoteText=Space$(UBound(vAttach)+1)和vbCrLf
.MsgNoteText=txtBody&vbCrLf
对于i=0至UBound(vAttach)
.AttachmentIndex=i
.AttachmentPosition=i
.AttachmentType=mapData
.AttachmentName=GetFileFromPath(vAttach(i))
.AttachmentPathName=vAttach(i)
接下来我
StatusBar1.Panels(1).Text=“状态:发送”
.发送真实
以
更多信息:

我正在取得一些进展。此错误与outlook中的电子邮件类型不是SMTP有关。如果在“outlook撰写”对话框中的“发送到电子邮件”上,右键单击电子邮件地址,然后选择“outlook属性”,并将电子邮件类型更改为“SMTP”,则它将正常工作。显示的类型是电子邮件地址本身,有效值似乎是“mailto”和“smtp”。因此,如果我可以从vb6设置电子邮件类型,它应该可以修复错误

“答案”是什么

我真不敢相信没有解决这个问题的办法…

解决了

我意识到这个话题很可能对20世纪的任何编程人员都不感兴趣,但下面是解决方法:

.RecipAddress = "SMTP:" & txtTo
我突然想到了。:)

解决了

我意识到这个话题很可能对20世纪的任何编程人员都不感兴趣,但下面是解决方法:

.RecipAddress = "SMTP:" & txtTo

我突然想到了。:)

如果你能总结出实际问题是什么,它可能会帮助那些在未来遇到这种情况的人如果你能总结出实际问题是什么,它可能会帮助那些在未来遇到这种情况的人相反,有足够多的人,这可能是有用的!相反,有足够多的人在那里,这可能是有用的!