How to Send Mail from Excel VBA Script?

We found many people searching for VBA script to send SMTP email without using outlook or any other application. We have written a Macro and also shared the code below to send email from your itself.

Although most of the purposes of sending emails through Excel are solved with Mail Merge but it could be useful for sending plain emails in bulk with less efforts or could be used as a module in Excel VBA application for sending email. Download the Excel Mail sending Macro from here or use the written code in this page.

Download Excel Mail Aensinf Macro

You may also use below written code. All you need to do is open VBA Editor using ALT + F11 (Press Fn key also if your keyboard has.) shortcut key, Click on insert and insert a module. Copy and paste the below code and change following values:

  1. Replace with your server SMTP server address (E.g. for Gmail Accounts, for Yahoo Accounts)
  2. Replace 465 with your SMTP Server Port (E.g. 465 / 587 / 25). These ports could vary according to Encryption Type. Try using anyone of three.
  3. User Email ID should be your email id (E.g.
  4. Replace sender_password with your password
  5. Replace with email ID to whom you want to send email and should be same as we used earlier.

Note: Please make sure your account does not have Two Factor Authentication Enabled. Also if you are using Gmail account, "Allow less secure apps" in Sign in and secutiry settings should be ON.

Sub CDO_Mail_Small_Text()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Variant

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields

With Flds
.Item("") = 2
.Item("") = ""
.Item("") = 465
.Item("") = True
.Item("") = ""
.Item("") = "sender_password"
.Item("") = 1
End With

strbody = "Hey There," & vbNewLine & vbNewLine & _ "This is a test message from VBA Excel Mail sending Program. Thank you for using me." & vbNewLine & _
"Thank you" & vbNewLine & _

With iMsg
Set.Configuration = iConf
.To = ""
.From = ""
.Subject = "Mail Subject"
.TextBody = strbody
End With

Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Sub

The above code could be used for sending bulk email by just listing a list of email accounts in excel and looping through it.