Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Unicode C Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Unicode C) 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 C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkImapW.h>
#include <C_CkMailManW.h>
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    HCkImapW imap;
    BOOL success;
    const wchar_t *myYahooEmailAddress;
    const wchar_t *myGeneratedAppPassword;
    HCkMailManW mailman;
    HCkEmailW email;

    // 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 = CkImapW_Create();
    CkImapW_putPort(imap,993);
    CkImapW_putSsl(imap,TRUE);
    success = CkImapW_Connect(imap,L"imap.mail.yahoo.com");
    if (success == FALSE) {
        wprintf(L"%s\n",CkImapW_lastErrorText(imap));
        CkImapW_Dispose(imap);
        return;
    }

    myYahooEmailAddress = L"joe@yahoo.com";
    myGeneratedAppPassword = L"lrabkaprvntxdjmc";

    // Sign into the app/service using your normal username
    // Instead of your normal password, enter the app password above
    success = CkImapW_Login(imap,myYahooEmailAddress,myGeneratedAppPassword);
    if (success == FALSE) {
        wprintf(L"%s\n",CkImapW_lastErrorText(imap));
        CkImapW_Dispose(imap);
        return;
    }

    success = CkImapW_SelectMailbox(imap,L"Inbox");
    if (success == FALSE) {
        wprintf(L"%s\n",CkImapW_lastErrorText(imap));
        CkImapW_Dispose(imap);
        return;
    }

    wprintf(L"Yahoo IMAP all good!\n");
    CkImapW_Disconnect(imap);

    // --------------------------------------------
    // Now do Yahoo SMTP:

    mailman = CkMailManW_Create();

    CkMailManW_putSmtpHost(mailman,L"smtp.mail.yahoo.com");

    CkMailManW_putSmtpUsername(mailman,myYahooEmailAddress);
    CkMailManW_putSmtpPassword(mailman,myGeneratedAppPassword);

    CkMailManW_putSmtpSsl(mailman,TRUE);
    CkMailManW_putSmtpPort(mailman,465);

    email = CkEmailW_Create();
    CkEmailW_putSubject(email,L"This is a test");
    CkEmailW_putBody(email,L"This is a test");
    CkEmailW_putFromName(email,L"Joe");
    CkEmailW_putFromAddress(email,myYahooEmailAddress);
    // Please change the recipient before running this code..
    CkEmailW_AddTo(email,L"Chilkat",L"info@chilkatsoft.com");

    success = CkMailManW_SendEmail(mailman,email);
    if (success != TRUE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkImapW_Dispose(imap);
        CkMailManW_Dispose(mailman);
        CkEmailW_Dispose(email);
        return;
    }

    success = CkMailManW_CloseSmtpConnection(mailman);
    if (success != TRUE) {
        wprintf(L"Connection to SMTP server not closed cleanly.\n");
    }

    wprintf(L"Yahoo Mail Sent!\n");

    // ------------------------------------
    // Now do Yahoo POP3

    CkMailManW_putMailHost(mailman,L"pop.mail.yahoo.com");

    CkMailManW_putPopUsername(mailman,myYahooEmailAddress);
    CkMailManW_putPopPassword(mailman,myGeneratedAppPassword);

    CkMailManW_putMailPort(mailman,995);
    CkMailManW_putPopSsl(mailman,TRUE);

    success = CkMailManW_Pop3Connect(mailman);
    if (success != TRUE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkImapW_Dispose(imap);
        CkMailManW_Dispose(mailman);
        CkEmailW_Dispose(email);
        return;
    }

    success = CkMailManW_Pop3Authenticate(mailman);
    if (success != TRUE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkImapW_Dispose(imap);
        CkMailManW_Dispose(mailman);
        CkEmailW_Dispose(email);
        return;
    }

    wprintf(L"Connected and authenticated with Yahoo POP Mail Server.\n");


    CkImapW_Dispose(imap);
    CkMailManW_Dispose(mailman);
    CkEmailW_Dispose(email);

    }

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.