cadsys-chemnitz
Goto Top

Mail senden

Ich hab folgendes Problem. Ich habe ein Excelfile das automatisch erzeugt wird. In Diesen liegt ein vollständiges Infoangebot für unseren Kunden.

Dieses will ich per MAil verschicken, der Code sieht so aus:


    Private Sub InfoangebotPerMailToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InfoangebotPerMailToolStripMenuItem.Click

        Dim msgBody

        msgBody = "Im Anhang finden Sie Ihr Infoangebot!"  

        MySendMail("tfuchs@xxx.de", msgBody, "Ihr Infoangebot.")  
    End Sub

    Sub MySendMail(ByVal Recipient, ByVal msg, ByVal subject)

        Dim OpenFileDialog As New OpenFileDialog
        OpenFileDialog.InitialDirectory = Kunden & "\"  
        OpenFileDialog.Filter = "Textdateien (*.xls)|*.xls"  
        OpenFileDialog.ShowDialog(Me)
        Dim FileName As String = OpenFileDialog.FileName

        Dim objSession, oInbox, colMessages, oMessage, colRecipients

        objSession = CreateObject("MAPI.Session")  
        objSession.Logon("Outlook")  

        oInbox = objSession.Inbox
        colMessages = oInbox.Messages
        oMessage = colMessages.Add()
        colRecipients = oMessage.Recipients

        colRecipients.Add(Recipient)
        colRecipients.Resolve()

        oMessage.Subject = subject
        oMessage.Text = msg
        oMessage.AttachmentPathName = FileName

        oMessage.Send()

        objSession.Logoff()
        objSession = Nothing

    End Sub

Bei der Zeile

        oMessage.AttachmentPathName = FileName

kommt eine Fehlermeldung:

Der offentliche Member AttachmentPathName für den Typ Message wurde nicht gefunden.

Wenn ich diese Zeile entferne geht es einwandfrei nur fehlt dann der Anhang. Am fehlenden Verweis kann es nicht liegen weil die anderen oMessage. Befehle ja gehen. Und laut MSDN lautet der Befehl oMessage.AttachmentPathName = FileName .

Wo liegt der Fehler ? Hat einer eine Idee?

Content-Key: 113921

Url: https://administrator.de/contentid/113921

Printed on: April 23, 2024 at 06:04 o'clock

Member: AndreasHoster
AndreasHoster Apr 15, 2009 at 13:51:53 (UTC)
Goto Top
Aus der MS Webseite (http://msdn.microsoft.com/en-us/library/aa228327(VS.60).aspx):
Specifies the full path name of the currently indexed attachment. This property is not available at design time. It is read-only unless MsgIndex is set to -1.

Ich sehe nicht, daß MsgIndex auf -1 gesetzt ist.
Und dann muß man noch den AttachmentIndex erhöhen (http://msdn.microsoft.com/en-us/library/aa228313(VS.60).aspx):
To add a new attachment, set the AttachmentIndex to a value greater than or equal to the current attachment count while in the compose buffer (MsgIndex = -1). The AttachmentCount property is updated automatically to reflect the implied new number of attachments.

Ob das alles war kann ich nicht sagen, bin Outlook frei.