Yahoo Mail - SMTP, IMAP, POP Authentication with App Password
See more Yahoo Mail Examples
An application can read and send email from Yahoo mail accounts, but now it must use an "application password" rather then the account owner's password.Let's say your application is "Xyz". Each Yahoo Mail account owner would first need to go to the "Account Security" tab in her Yahoo Mail account settings and create an App Password. It is the App Password that is used with SMTP, IMAP, and POP instead of the normal account password. The Yahoo Mail account owner can choose to create individual app passwords, one for each app, or can create a single app password that she might use for all apps. Ultimately, this is just a way to allow the user to associate passwords with individual apps such that a password for an individual app can be changed or revoked without affecting other apps. This is also better security. It's the same idea as using a password manager. Rather than using the same password for all online accounts, each individual account has a generated password that is managed by a password manager service or program with a single master password.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoImap
String sMyYahooEmailAddress
String sMyGeneratedAppPassword
Handle hoMailman
Variant vEmail
Handle hoEmail
String sTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// To authenticate with Yahoo Mail in SMTP, IMAP, or POP, the full email address is the username, and a generated app password is the password.
// See Yahoo Mail Generate and manage third-party app passwords
// The information at the above linked web page is:
// Some older, third-party email apps (that do not use our Yahoo branded sign-in page) require you to enter a single password for login credentials.
// To access your Yahoo Mail account on these apps, you'll need to generate and use an app password.
// An app password is a long, randomly generated code that gives a non-Yahoo app permission to access your Yahoo account.
// You�ll only need to provide this code once to sign in to your third-party email app.
//
// Generate an app password
//
// Sign in to your Yahoo Account Security page.
// Click Generate app password or Generate and manage app passwords.
// Enter your app's name in the text field.
// Click Generate password.
// Follow the instructions below the app password.
// Click Done.
//
// Use this app password and your email address to sign in to your email app.
// ------
// NOTE: The comment "You�ll only need to provide this code once to sign in to your third-party email app." is assuming your app
// is persisting the user's password such that it re-uses it to authenticate each time it connects to the mail server.
// All SMTP, IMAP, or POP sessions must authenticate with each new connection/session.
// ------
// First, let's demonstrate IMAP...
Get Create (RefClass(cComChilkatImap)) To hoImap
If (Not(IsComObjectCreated(hoImap))) Begin
Send CreateComObject of hoImap
End
Set ComPort Of hoImap To 993
Set ComSsl Of hoImap To True
Get ComConnect Of hoImap "imap.mail.yahoo.com" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Move "joe@yahoo.com" To sMyYahooEmailAddress
Move "lrabkaprvntxdjmc" To sMyGeneratedAppPassword
// Sign into the app/service using your normal username
// Instead of your normal password, enter the app password above
Get ComLogin Of hoImap sMyYahooEmailAddress sMyGeneratedAppPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComSelectMailbox Of hoImap "Inbox" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Yahoo IMAP all good!"
Get ComDisconnect Of hoImap To iSuccess
// --------------------------------------------
// Now do Yahoo SMTP:
Get Create (RefClass(cComChilkatMailMan)) To hoMailman
If (Not(IsComObjectCreated(hoMailman))) Begin
Send CreateComObject of hoMailman
End
Set ComSmtpHost Of hoMailman To "smtp.mail.yahoo.com"
Set ComSmtpUsername Of hoMailman To sMyYahooEmailAddress
Set ComSmtpPassword Of hoMailman To sMyGeneratedAppPassword
Set ComSmtpSsl Of hoMailman To True
Set ComSmtpPort Of hoMailman To 465
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "This is a test"
Set ComBody Of hoEmail To "This is a test"
Set ComFromName Of hoEmail To "Joe"
Set ComFromAddress Of hoEmail To sMyYahooEmailAddress
// Please change the recipient before running this code..
Get ComAddTo Of hoEmail "Chilkat" "info@chilkatsoft.com" To iSuccess
Get pvComObject of hoEmail to vEmail
Get ComSendEmail Of hoMailman vEmail To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComCloseSmtpConnection Of hoMailman To iSuccess
If (iSuccess <> True) Begin
Showln "Connection to SMTP server not closed cleanly."
End
Showln "Yahoo Mail Sent!"
// ------------------------------------
// Now do Yahoo POP3
Set ComMailHost Of hoMailman To "pop.mail.yahoo.com"
Set ComPopUsername Of hoMailman To sMyYahooEmailAddress
Set ComPopPassword Of hoMailman To sMyGeneratedAppPassword
Set ComMailPort Of hoMailman To 995
Set ComPopSsl Of hoMailman To True
Get ComPop3Connect Of hoMailman To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComPop3Authenticate Of hoMailman To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Connected and authenticated with Yahoo POP Mail Server."
End_Procedure