1

私は次のことをしようとしています:

  • VBA を使用して SMTP 電子メールを生成する
  • 電子メールに埋め込まれた InfoPath フォームを表示する
    • これは Access データベースにリンクされます

残念ながら、CDO を使用して発信 SMTP メッセージを正しく構成できませんでした。

残念ながら C# にあるこの投稿で見つかった情報に基づいて作成しており、この機能の一部は VB/VBA に直接マップされていません。具体的には、"Message.Headers" の部分は、CDO.Message クラスが持つプロパティではありません。

添付ファイルを変更して正しく追加することはできましたが、次の作業中:

    .fields("urn:schemas:mailheader:Message-Class") = "IPM.InfoPathForm.InfoPath"
    .fields("urn:schemas:mailheader:Content-Class") = "InfoPathForm.InfoPath"

フォームが電子メールに表示されません (xml と xsn の両方が添付ファイルとして表示され、埋め込みフォームとして表示されません)。

有効なフォーム (手動で生成) と無効なフォーム (プログラム的に生成) の電子メール ソースを比較しても、他に何を変更する必要があるか判断できませんでした。電子メールにはさらにいくつかのコンテンツ タグがあります。1 つは次のとおりです。

Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

<html dir=3D"ltr" id=3D"L044F61201A9E6BE2"> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 1"> </head> 
(etc, there is a bunch more)

もう1つは次のとおりです。

Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

この下には、実際のフォームからのテキストがあります。

おそらく、これらのセクションは、正しく使用していない設定によって自動的に生成される必要があります。

メールを生成するために使用しているコードは次のとおりです。2 つの添付ファイルは有効であり、InfoPath を使用して電子メールを送信すると正しく表示されるフォームから保存したものであることに注意してください。

Sub testSendingEmail()

    On Error GoTo errHndlr 'boring error handling

    Dim myAttach(1 To 2) As String
    Dim myContentType(1 To 2) As String

    myAttach(1) = "C:\Users\UserID\Desktop\infoPath\outlooksaves\Form1.xml"
    myAttach(2) = "C:\Users\UserID\Desktop\infoPath\outlooksaves\Add Projects Table Form.xsn"

    myContentType(1) = "application/x-microsoft-InfoPathForm"
    myContentType(2) = "application/x-microsoft-InfoPathFormTemplate"



    Dim mailMessage As Object

    Set mailMessage = CreateObject("CDO.Message")
    With mailMessage
        .Subject = "Test Automatic Subject 363"
        .from = "donotreply@a.com"
        .To = "TestEmail@gmail.com"

        .AddAttachment myAttach(1)
        .AddAttachment myAttach(2)
        .Attachments.Item(1).ContentMediaType = myContentType(1)
        .Attachments.Item(2).ContentMediaType = myContentType(2)

        'testing - this isn't right :(
        .fields("urn:schemas:mailheader:Message-Class") = "IPM.InfoPathForm.InfoPath"
        .fields("urn:schemas:mailheader:Content-Class") = "InfoPathForm.InfoPath"

        With .Configuration.fields
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailserve"
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            '.Item("http://schemas.microsoft.com/cdo/configuration/mailheader:Content-Class") = "InfoPathForm.InfoPath"
            .Update
        End With

        '.BodyPart.ContentClass = "InfoPathForm.InfoPath"
        'from C# code
        '.Headers.Add "Content-Class", "InfoPathForm.InfoPath"
        ' .Headers.Add "Message-Class", "IPM.InfoPathForm.InfoPath"
        .Send

    End With

    Exit Sub

errHndlr:
    Debug.Print "Error!" & " " & Err.Description

End Sub
4

1 に答える 1