Forum Discussion
Send Email using yahoo smtp
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("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.yahoo.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 ' Basic (clear-text) authentication
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "email address removed for privacy reasons"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your_yahoo_password"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True ' Use SSL
.Update
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."
.Send
End With
MsgBox "Email sent successfully!", vbInformation
ExitSub:
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
Exit Sub
ErrHandler:
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.