Sample code for 30+ languages & platforms
Objective-C

Verify SMTP Login (Connect and Authenticate)

See more SMTP Examples

Demonstrates the Chilkat MailMan.VerifySmtpLogin method, which tests whether Chilkat can connect to the configured SMTP server and successfully authenticate using the current SMTP authentication settings. This example configures the SMTP host and credentials and verifies login.

Background: This goes one step further than VerifySmtpConnection: after reaching the server it also performs the AUTH exchange with your username and password (or OAuth2 token). It's the ideal preflight check when validating credentials or diagnosing "why won't my mail send?" — a false result after a good connection points squarely at bad credentials or an unsupported auth method rather than a network problem.

Chilkat Objective-C Downloads

Objective-C
#import <CkoMailMan.h>

BOOL success = NO;

//  Demonstrates the MailMan.VerifySmtpLogin method, which tests whether Chilkat can connect
//  to the configured SMTP server and successfully authenticate using the current SMTP
//  authentication settings.

CkoMailMan *mailman = [[CkoMailMan alloc] init];

//  Configure the SMTP server connection.
mailman.SmtpHost = @"smtp.example.com";
mailman.SmtpPort = [NSNumber numberWithInt:465];
mailman.SmtpSsl = YES;
mailman.SmtpUsername = @"user@example.com";
mailman.SmtpPassword = @"myPassword";

//  Test both connectivity and authentication.
BOOL loggedIn = [mailman VerifySmtpLogin];

if (loggedIn == YES) {
    NSLog(@"%@",@"Successfully connected and authenticated with the SMTP server.");
}
else {
    NSLog(@"%@",@"SMTP connect or login failed.");
}