Unable to send email using VBA

Unable to send email using VBA

Issue Faced -
I am trying to send email using vba, but throws me error - 

Code used - 
Sub SendEmailUsingzoho(sTrnrEmail, saveFileName)
    On Error GoTo Err:

    'late binding
    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
        .From = "****"
        .To = sTrnrEmail
        .CC = ""
        .BCC = ""
        .Subject = "Salary Slip for " & Format(Now(), "mmmm, yyyy")
        .TextBody = "Hello, Please find attached the Salary Slip for " & Format(Now(), "mmmm, yyyy") & "! Let us know if you have any questions about the same. Thanks :)"
        .AddAttachment saveFileName
    End With


    With fields
        .Item(msConfigURL & "/smtpusessl") = True               'Enable SSL Authentication
        .Item(msConfigURL & "/smtpauthenticate") = 1            'SMTP authentication Enabled
        .Item(msConfigURL & "/smtpserver") = "smtp.zoho.com"    'Set the SMTP server details
        .Item(msConfigURL & "/smtpserverport") = 25            'Set the SMTP port Details
        .Item(msConfigURL & "/sendusing") = 2                   'Send using default setting
        .Item(msConfigURL & "/sendusername") = "**"  'Your zoho address
        .Item(msConfigURL & "/sendpassword") = "*********"   'Your password or App Password
        .Update                                              'Update the configuration fields
    End With
    NewMail.Configuration = mailConfig
    NewMail.Send
    
    MsgBox "Your email has been sent", vbInformation

Exit_Err:
    'Release object memory
    Set NewMail = Nothing
    Set mailConfig = Nothing
    End

Err:
    Select Case Err.Number
    Case -2147220973  'Could be because of Internet Connection
        MsgBox "Check your internet connection." & vbNewLine & Err.Number & ": " & Err.Description
    Case -2147220975  'Incorrect credentials User ID or password
        MsgBox "Check your login credentials and try again." & vbNewLine & Err.Number & ": " & Err.Description
    Case Else   'Report other errors
        MsgBox "Error encountered while sending email." & vbNewLine & Err.Number & ": " & Err.Description
    End Select

    Resume Exit_Err

End Sub



      • Sticky Posts

      • Zoho Mail POP & IMAP Server Details

        Hello all! We have been receiving a number of requests regarding the errors while configuring or using Zoho Mail account in POP/ IMAP clients. The server details vary based on your account type and the Datacenter in which your account is setup. Ensure
      • Important update on Group Management | Zoho Mail

        Dear Zoho Mail Community, This post is to inform you all of the following updates on the Group Management in Zoho Mail. Group Member Addition: If a group member is added to an organization group in a Zoho Application, the member will be automatically
      • Mastering email etiquette and best practices to follow in Zoho Mail

        Hello Zoho Mail Community, We’re thrilled to invite you all to our upcoming webinar: Mastering email etiquette and best practices to follow in Zoho Mail. Join our live webinar for expert etiquette tips to enhance your professionalism and elevate your
      • 📣 📣 ZUG Meetups India - Explore Hybrid Workspaces using Zoho Workplace - Meet and Learn! 🧑🏽‍💻🧑🏽‍💻

        We are excited to announce the User Community initiative to meet you all in person and help you explore the need of the hour - Hybrid Workspaces using Zoho Workplace. We aim to help you to setup your Digital Workplace effectively so that your employees
      • Announcing Zoho Mail - Inactive user Policy

        Dear Zoho Mail users, Thanks to all of you for your continuous support.  We have recently started implementing the Inactive User Policy, for Zoho Mail.  A user is considered as inactive, if the user has not logged in to the Zoho mail account for a period of more than 120 days. The login through POP, IMAP and Active Sync are all taken into account for tracking the period of inactivity.  Whoever received the communication need not panic, as we have just communicated our policy to all the users.  To