VB6 - Send Email With Attachment - AdminSystem Software Limited

  1. Home
  2. EASendMail SMTP Component
  3. KB
  4. Example Codes
  5. VB/VBA
  6. VB6 - Send Email with Attachment

Tutorial Index

  • VB6 - Send email using SMTP server
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send email using SMTP server - example
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send email over SSL on 465 port
    • SSL and TLS
    • TLS 1.2 protocol
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send email over SSL on 465 port - example
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send email over TLS on 25 or 587 port
    • SSL and TLS
    • TLS 1.2 protocol
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send email over TLS on 25 or 587 port - example
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send email using Gmail SMTP server
    • Gmail App Password
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send email using Gmail SMTP server - example
    • Gmail SMTP OAUTH
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send email using Yahoo SMTP server
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send email using Yahoo SMTP server - example
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send email using Hotmail, Outlook.com, Office 365
    • App Password and SmtpClientAuthenticationDisabled
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send email using Hotmail, Outlook.com, Office 365 - example
    • Hotmail SMTP OAUTH
    • Office365 SMTP/EWS/Ms Graph API OAUTH
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Email queue with EASendMail Service
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send email using queue service - example
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Email queue with EASendMail Service - database
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • MS Access x64 Driver
    • VB6 - Send email to queue service - database
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send email using MX DNS lookup - smart host
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send email using MX DNS lookup - smart host - example
    • Important notice
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Request delivery receipt and read receipt - email trace
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Request delivery receipt and read receipt - example
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Validate email address syntax and test email address
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Test email address - example
    • How does it work?
    • Why we don’t recommend testing email address?
    • Recommended solution
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - DomainKeys and DKIM signature
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - DomainKeys and DKIM signature - example
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send HTML email
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send HTML email - example
    • Import Html to email directly
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send email with attachment
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send email with attachment - example
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send HTML email with embedded images
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send HTML email with embedded images - example
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Sign email - S/MIME
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Sign email - S/MIME - example
    • Signature algorithm
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Encrypt email - S/MIME
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Encrypt email - S/MIME - example
    • Encryption algorithm
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Send EML file
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • VB6 - Send EML file - example
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6 - Sign email (RSASSA-PSS + SHA256) and encrypt email (RSAES-OAEP + AES 128/196/256 + SHA256) based on EDIFACT rule - S/MIME
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • EDIFACT rule in EUROPE
    • EASendMail ActiveX Object with Bouncy Castle
    • VB6 - Sign email with RSASSA-PSS + SHA256 - EDIFACT - S/MIME - example
    • VB6 - Encrypt email with RRSAES-OAEP + AES 128/192/256 + SHA256 - EDIFACT - S/MIME - example
    • VB6 - Sign email with RSASSA-PSS + SHA256 and encrypt email with RRSAES-OAEP + AES 128/192/256 + SHA256 - EDIFACT - S/MIME - example
    • TLS 1.2 protocol
    • 32bit/x64 ActiveX DLL
    • Distribution
  • VB6/ASP - Send email using Google/Gmail OAuth 2.0 authentication
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • Create project in Google Developers Console
    • OAuth consent screen
    • Create credentials (OAuth client id)
    • Enable Gmail API
    • Edit scopes
    • API scopes
    • Authorized Redirect URIs
    • Test and publish your app
    • Enable TLS Strong Encryption Algorithms in .NET 2.0 and .NET 4.0
    • Use client id and client secret to request access token
    • Access token expiration and refresh token
    • VB6 - Send email using Google OAuth + Gmail SMTP server
    • VBScript/ASP - Send email using Google OAuth + Gmail SMTP server
    • TLS 1.2 protocol
    • Related links
  • VB6/ASP - Send email using Gmail/G Suite OAuth 2.0 in background service (service account)
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • Google Service Account
    • Create project in Google Developers Console
    • Create service account in current project
    • Create service key
    • Enable Gmail API
    • Authorize service account by G Suite administrator
    • Enable TLS Strong Encryption Algorithms in .NET 2.0 and .NET 4.0
    • Access token lifetime
    • VB6/ASP - Send email using Gmail/G Suite OAuth 2.0 with service account - example
    • TLS 1.2 protocol
    • Related links
  • VB6/ASP - Send email using Microsoft OAuth 2.0 (Modern Authentication) from Hotmail/Outlook Account
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • Create your application in Azure Portal
    • Register application
    • Single tenant and multitenant in account type
    • Assign API permission
    • EWS API permission
    • Authentication and redirect uri
    • Client Id and client secrets
    • Branding and verify publisher
    • Client id and tenant
    • Enable TLS Strong Encryption Algorithms in .NET 2.0 and .NET 4.0
    • Use client id and client secret to request access token
    • Access token expiration and refresh token
    • VB6 - Send email using Microsoft OAuth + Hotmail/Outlook/Live SMTP server
    • VBScript - Send email Using Microsoft OAuth + Hotmail/Outlook Live SMTP server in ASP
    • TLS 1.2 protocol
    • EA Oauth Service for Office 365
    • Related links
  • VB6/ASP - Send email using Microsoft OAuth 2.0 (Modern Authentication) + SMTP/EWS/Ms Graph API protocol from Office 365 account
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • Create your application in Azure Portal
    • Register application
    • Single tenant and multitenant in account type
    • Assign API permission
    • EWS API permission
    • Authentication and redirect uri
    • Client Id and client secrets
    • Branding and verify publisher
    • Client id and tenant
    • Enable TLS Strong Encryption Algorithms in .NET 2.0 and .NET 4.0
    • Use client id and client secret to request access token
    • Access token expiration and refresh token
    • VB6 - Send email using Microsoft OAuth + Office 365 SMTP protocol
    • VB6 - Send email using Microsoft OAuth + Office 365 EWS protocol
    • VB6 - Send email using Microsoft OAuth + Office 365 Ms Graph API protocol
    • VBScript - Send email using Microsoft OAuth + Office 365 SMTP/EWS/Ms Graph API protocol in ASP
    • TLS 1.2 protocol
    • EA Oauth Service for Office 365
    • Related links
  • VB6/ASP - Send email using Microsoft OAuth 2.0 (Modern Authentication) + EWS/Ms Graph API/SMTP protocol from Office 365 in background service
    • Installation
    • Add reference in VB6
    • Add reference in VBA (EXCEL/Access/Outlook)
    • Office 365 OAuth 2.0 client credentials grant
    • Register the application in Azure Portal
    • Register application
    • Find the application id (client id) and tenant id
    • Assign API permission
    • Graph API permission
    • Add Mail.Send and Mail.ReadWrite permission
    • EWS and SMTP/POP/IMAP permission
    • Add full_access_app permission
    • Add POP.AccessAsApp permission
    • Add IMAP.AccessAsApp permission
    • Add SMTP.AccessAsApp permission
    • Complete permissions list
    • Grant admin consent in API permission
    • Create client secret
    • Store client secret value
    • VB6/ASP - Send email using Microsoft Ms Graph API + OAuth from Office 365 account in background service - example
    • VB6/ASP - Send email using EWS + Microsoft OAuth from Office 365 account in background service - example
    • Register SMTP/POP/IMAP service principals in Exchange
    • Find APPLICATION_ID and OBJECT_ID
    • Open Exchange Online PowerShell
    • Create service principal
    • Query service principal
    • Add permission to specific user
    • Query permission
    • VB6/ASP - Send email using SMTP + Microsoft OAuth from Office 365 account in background service - example
    • Access token lifetime
    • TLS 1.2 protocol
    • EA Oauth Service for Office 365
    • Related links
VB6 - Send email with attachment¶

The following vb6 example codes demonstrate how to send email with file attachment using SMTP server.

To send an email with file attachment, we need to use AddAttachment method. This method can attach a file to the email message from local disk or a remote URL.

Sections:

  • Installation
  • Add reference in VB6
  • Add reference in VBA (EXCEL/Access/Outlook)
  • VB6 - Send email with attachment - example
  • TLS 1.2 protocol
  • 32bit/x64 ActiveX DLL
  • Distribution

Installation¶

EASendMail is a SMTP component which supports all operations of SMTP/ESMTP protocols (RFC 821, RFC 822, RFC 2554). Before you can use the following example codes, you should download the EASendMail Installer and install it on your machine at first.

Add reference in VB6¶

To use EASendMail SMTP ActiveX Object in your project, the first step is “Add reference of EASendMail to your project”. Please select menu -> Project -> References -> and select EASendMailObj ActiveX Object, click OK, the reference will be added to current project, and you can start to use it to send email in your VB6 project.

Add reference in VBA (EXCEL/Access/Outlook)¶

Open VBA IDE by press Alt+F11, Please select menu -> Tools -> References -> and select EASendMailObj ActiveX Object, click OK, the reference will be added to current VBA project, and you can start to use it to send email in your VBA project.

add reference in VB 6.0

VB6 - Send email with attachment - example¶

The following example codes demonstrate sending email with attachment. In order to run it correctly, please change SMTP server, user, password, sender, recipient value to yours.

Note

To get full sample projects, please download and install EASendMail on your machine.

Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 Private Sub btnSendMail_Click() Dim oSmtp As New EASendMailObjLib.Mail oSmtp.LicenseCode = "TryIt" ' Set your sender email address oSmtp.FromAddr = "test@emailarchitect.net" ' Add recipient email address oSmtp.AddRecipientEx "support@emailarchitect.net", 0 ' Set email subject oSmtp.Subject = "test HTML email from VB 6.0 project with attachment" ' Set HTML body format oSmtp.BodyFormat = 1 ' Set HTML body text oSmtp.BodyText = "<font size=5>This is</font> <font color=red><b>a test</b></font>" ' Add attachment from local disk If oSmtp.AddAttachment( "c:\test.doc" ) <> 0 Then MsgBox "Failed to add attachment with error:" & oSmtp.GetLastErrDescription() End If ' Add attachment from remote website If oSmtp.AddAttachment( "http://www.emailarchitect.net/webapp/img/logo.jpg" ) <> 0 Then MsgBox "Failed to add attachment with error:" & oSmtp.GetLastErrDescription() End If ' Your SMTP server address oSmtp.ServerAddr = "smtp.emailarchitect.net" ' User and password for ESMTP authentication, if your server doesn't require ' User authentication, please remove the following codes. oSmtp.UserName = "test@emailarchitect.net" oSmtp.Password = "testpassword" ' ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically oSmtp.ConnectType = ConnectTryTLS ' If your server uses 587 port ' oSmtp.ServerPort = 587 ' If your server uses 25/587/465 port with SSL/TLS ' oSmtp.ConnectType = ConnectSSLAuto ' oSmtp.ServerPort = 25 ' 25 or 587 or 465 MsgBox "start to send email ..." If oSmtp.SendMail() = 0 Then MsgBox "email was sent successfully!" Else MsgBox "failed to send email with the following error:" & oSmtp.GetLastErrDescription() End If End Sub

TLS 1.2 protocol¶

TLS is the successor of SSL, more and more SMTP servers require TLS 1.2 encryption now.

If your operating system is Windows XP/Vista/Windows 7/Windows 2003/2008/2008 R2/2012/2012 R2, you need to enable TLS 1.2 protocol in your operating system like this:

Enable TLS 1.2 on Windows XP/Vista/7/10/Windows 2008/2008 R2/2012

32bit/x64 ActiveX DLL¶

Seperate builds of run-time dll for 32 and x64 platform

File Platform
Installation Path\Lib\native\x86\EASendMailObj.dll 32 bit
Installation Path\Lib\native\x64\EASendMailObj.dll 64 bit

Distribution¶

  • Standard EXE

    For VB6, C++, Delphi or other standard exe application, you can distribute EASendMailObj.dll with your application to target machine without COM-registration and installer. To learn more detail, please have a look at Registration-free COM with Manifest File.

  • Script

    For ASP, VBScript, VBA, MS SQL Stored Procedure, you need to install EASendMail on target machine by EASendMail installer, both 32bit/x64 DLL are installed and registered.

  • «
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • »

Appendix

  • Send Email in VB 6.0 - Tutorial
  • EASendMail SMTP Component SDK
  • Process Bounced Email (Non-Delivery Report) and Email Tracking
  • Bulk Email Sender Guidelines
  • Work with Email Queue

Comments

If you have any comments or questions about above example codes, please click here to add your comments.

Share
  • Facebook
  • Google+
  • Twitter
  • LinkedIn
See Also
  • C#
  • VB.NET
  • C++/CLI/CLR
  • VB6
  • C++
  • Delphi
  • Download

Từ khóa » Visual Basic Code To Send Email With Attachment