Send Email using yahoo smtp

Copper Contributor


I want to send email from vba userform and I have used the following codes with failure. Please help me to make it correct. Thanks in advance.


Macro is as follows-


On Error GoTo Err

Dim NewMail As Object
Dim mailConfig As Object
Dim fields As Variant
Dim msConfigURL As String

Set NewMail = CreateObject("CDO.Message")
Set mailConfig = CreateObject("CDO.Configuration")

' load all default configurations
mailConfig.Load -1

Set fields = mailConfig.fields

'Set All Email Properties

With NewMail
.Subject = "Test Mail from"
.From = "email address removed for privacy reasons"
.To = "email address removed for privacy reasons"
.CC = ""
.BCC = ""
.TextBody = ""
End With

msConfigURL = ""

With fields
'Enable SSL Authentication
.Item(msConfigURL & "/smtpusessl") = True

'Make SMTP authentication Enabled=true (1)
.Item(msConfigURL & "/smtpauthenticate") = 1

'Set the SMTP server and port Details
'To get these details you can get on Settings Page of your yahoo Account
.Item(msConfigURL & "/smtpserver") = ""
.Item(msConfigURL & "/smtpserverport") = 465 '25 '587 ' 465
.Item(msConfigURL & "/sendusing") = 2

'Set your credentials of your yahoo Account
.Item(msConfigURL & "/sendusername") = "email address removed for privacy reasons"
.Item(msConfigURL & "/sendpassword") = "nessa123usa"

'Update the configuration fields

End With

NewMail.Configuration = mailConfig
MsgBox ("Mail has been Sent")


Set NewMail = Nothing
Set mailConfig = Nothing
' End
Exit Sub

Select Case Err.Number

Case -2147220973 'Could be because of Internet Connection
MsgBox " Could be no Internet Connection !! -- " & Err.description

Case -2147220975 'Incorrect credentials User ID or password
MsgBox "Incorrect Credentials !! -- " & Err.description

Case Else 'Rest other errors
MsgBox "Error occured while sending the email !! -- " & Err.description
End Select

Resume Exit_Err

3 Replies


To send an email using Yahoo SMTP in VBA, you can use the following code. Make sure to replace the placeholders with your actual email address and password.

Vba Code is untested; please backup your file before.

Sub SendEmailUsingYahooSMTP()
    On Error GoTo ErrHandler

    Dim iMsg As Object
    Dim iConf As Object
    Dim Flds As Object

    ' Email Configuration
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields

    ' SMTP Configuration
    With Flds
        ' Set configuration fields for Yahoo SMTP
        .Item("") = 2
        .Item("") = ""
        .Item("") = 465
        .Item("") = 60
        .Item("") = 1 ' Basic (clear-text) authentication
        .Item("") = "email address removed for privacy reasons"
        .Item("") = "your_yahoo_password"
        .Item("") = True ' Use SSL
    End With

    ' Email Properties
    With iMsg
        Set .Configuration = iConf
        .To = "email address removed for privacy reasons"
        .CC = ""
        .BCC = ""
        .From = "email address removed for privacy reasons"
        .Subject = "Test Email"
        .TextBody = "This is a test email sent using Yahoo SMTP in VBA."
    End With

    MsgBox "Email sent successfully!", vbInformation

    Set iMsg = Nothing
    Set iConf = Nothing
    Set Flds = Nothing
    Exit Sub

    MsgBox "An error occurred: " & Err.Description, vbCritical
    Resume ExitSub
End Sub


Make sure to enable "Less Secure App Access" in your Yahoo account settings and generate an "App Password" for your application to use. Replace "email address removed for privacy reasons" and "your_yahoo_password" with your Yahoo email address and app password.

Note: Using hard-coded credentials in your VBA code is not recommended for security reasons. Always ensure that your code is secure, and consider other secure methods for storing credentials if the code will be shared or distributed. The text was created with the help of AI.


My answers are voluntary and without guarantee!


Hope this will help you.


Was the answer useful? Mark as best response and like it!

This will help all forum participants.

Thanks a lot Sir, for the response. I will test it and let you know. Thanks again.
Thanks a lot Sir, for the response. I will test it and let you know soon. Thanks again.