AddAttachmentEx Method

Attach a file or URL as attachment to current email with customized file name.

C++: HRESULT AddAttachmentEx(BSTR strFile, BSTR strAlt, long* pVal)
Visual Basic: AddAttachmentEx(strFile As String, strAlt As String) As Long


File or URL to be attached.
File name to be displayed in current email.

Return Value

If this method succeeds, the return value is zero; otherwise the return value isnon-zero.


strFile must be a valid local file with full path or a valid URL.


[Visual Basic] To get the full samples of EASendMail, please refer to Samples section.

[VB6, VBA - Send Email with Attachment]

Const ConnectNormal = 0
Const ConnectSSLAuto = 1
Const ConnectSTARTTLS = 2
Const ConnectDirectSSL = 3
Const ConnectTryTLS = 4

Private Sub SendEmail()
    Dim oSmtp As EASendMailObjLib.Mail
    Set oSmtp = New EASendMailObjLib.Mail
    oSmtp.LicenseCode = "TryIt"

    ' Your SMTP server address
    oSmtp.ServerAddr = ""

    ' User and password for ESMTP authentication
    oSmtp.UserName = ""
    oSmtp.Password = "testpassword"

    ' ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically
    oSmtp.ConnectType = ConnectTryTLS

    oSmtp.FromAddr = ""

    oSmtp.AddRecipient "Support Team", "", 0
    oSmtp.BodyText = "Hello, this is a test...."

    If oSmtp.AddAttachmentEx("c:\test.doc", "mytest.doc") <> 0 Then
        MsgBox "failed to add attachment"
        MsgBox oSmtp.GetLastErrDescription()
        Exit Sub
    End If

    If oSmtp.SendMail() = 0 Then
        MsgBox "Message delivered!"
        MsgBox oSmtp.GetLastErrDescription()
    End If
End Sub

See Also

AddAttachment Method
AddInline Method

Online Examples

VB6- Send Email with Attachment
VB6 - Send Email with Embedded Images
Delphi - Send Email with Attachment
Delphi - Send Email with Embedded Images
Visual C++ - Send Email with Attachment
Visual C++ - Send Email with Embedded Images