Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Yahoo Mail - SMTP, IMAP, POP Authentication with App PasswordSee more Yahoo Mail ExamplesAn 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.
IncludeFile "CkImap.pb" IncludeFile "CkEmail.pb" IncludeFile "CkMailMan.pb" Procedure ChilkatExample() ; 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. ; Youll 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 "Youll 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... imap.i = CkImap::ckCreate() If imap.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkImap::setCkPort(imap, 993) CkImap::setCkSsl(imap, 1) success.i = CkImap::ckConnect(imap,"imap.mail.yahoo.com") If success = 0 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf myYahooEmailAddress.s = "joe@yahoo.com" myGeneratedAppPassword.s = "lrabkaprvntxdjmc" ; Sign into the app/service using your normal username ; Instead of your normal password, enter the app password above success = CkImap::ckLogin(imap,myYahooEmailAddress,myGeneratedAppPassword) If success = 0 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf success = CkImap::ckSelectMailbox(imap,"Inbox") If success = 0 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf Debug "Yahoo IMAP all good!" CkImap::ckDisconnect(imap) ; -------------------------------------------- ; Now do Yahoo SMTP: mailman.i = CkMailMan::ckCreate() If mailman.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkMailMan::setCkSmtpHost(mailman, "smtp.mail.yahoo.com") CkMailMan::setCkSmtpUsername(mailman, myYahooEmailAddress) CkMailMan::setCkSmtpPassword(mailman, myGeneratedAppPassword) CkMailMan::setCkSmtpSsl(mailman, 1) CkMailMan::setCkSmtpPort(mailman, 465) email.i = CkEmail::ckCreate() If email.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkEmail::setCkSubject(email, "This is a test") CkEmail::setCkBody(email, "This is a test") CkEmail::setCkFromName(email, "Joe") CkEmail::setCkFromAddress(email, myYahooEmailAddress) ; Please change the recipient before running this code.. CkEmail::ckAddTo(email,"Chilkat","info@chilkatsoft.com") success = CkMailMan::ckSendEmail(mailman,email) If success <> 1 Debug CkMailMan::ckLastErrorText(mailman) CkImap::ckDispose(imap) CkMailMan::ckDispose(mailman) CkEmail::ckDispose(email) ProcedureReturn EndIf success = CkMailMan::ckCloseSmtpConnection(mailman) If success <> 1 Debug "Connection to SMTP server not closed cleanly." EndIf Debug "Yahoo Mail Sent!" ; ------------------------------------ ; Now do Yahoo POP3 CkMailMan::setCkMailHost(mailman, "pop.mail.yahoo.com") CkMailMan::setCkPopUsername(mailman, myYahooEmailAddress) CkMailMan::setCkPopPassword(mailman, myGeneratedAppPassword) CkMailMan::setCkMailPort(mailman, 995) CkMailMan::setCkPopSsl(mailman, 1) success = CkMailMan::ckPop3Connect(mailman) If success <> 1 Debug CkMailMan::ckLastErrorText(mailman) CkImap::ckDispose(imap) CkMailMan::ckDispose(mailman) CkEmail::ckDispose(email) ProcedureReturn EndIf success = CkMailMan::ckPop3Authenticate(mailman) If success <> 1 Debug CkMailMan::ckLastErrorText(mailman) CkImap::ckDispose(imap) CkMailMan::ckDispose(mailman) CkEmail::ckDispose(email) ProcedureReturn EndIf Debug "Connected and authenticated with Yahoo POP Mail Server." CkImap::ckDispose(imap) CkMailMan::ckDispose(mailman) CkEmail::ckDispose(email) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.