Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

728
Views
Mailkit SMTP - StartTLS & TLS flags

I am trying to connect to iCloud via SmtpClient

The settings I am using are as follows:

Server name: smtp.mail.me.com
SSL Required: Yes
If you see an error message when using SSL, try using TLS or STARTTLS instead.
Port: 587
SMTP Authentication Required: Yes - with relevant username and password

If I use SSL I get "Handshake failed due to unexpected packet format"

If I don't use SSL visual studio debugger hangs on connect.

I think the problem is I am not telling the SmtpClient to use tls but I cant find documentation on how to do this.

The code is as follows:

using (var client = new SmtpClient()) {
    client.Timeout = 1000 * 20;
    //client.Capabilities.
    client.AuthenticationMechanisms.Remove ("XOAUTH2");

    client.Connect("SMTP.mail.me.com", 587, false); //dies here
    //client.Connect(servername, port, useSsl);
    //can I set tls or starttls here??
    client.Authenticate(username, password);
    client.Send(FormatOptions.Default, message);
}

Am I able to set TLS or StartTLS manually. One thing I did try is the following but it did not seem to work

client.Connect(new Uri("smtp://" + servername + ":" + port + "/?starttls=true"));

Thanks for any help with this.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The Connect() method that you are using only allows enabling/disabling SSL-wrapped connections which is not the same thing as StartTLS.

Due to the confusion, I've implemented a separate Connect() method that makes this more obvious what is going on:

using (var client = new SmtpClient()) {
    // Note: don't set a timeout unless you REALLY know what you are doing.
    //client.Timeout = 1000 * 20;

    client.Connect ("smtp.mail.me.com", 587, SecureSocketOptions.StartTls);
    client.Authenticate (username, password);
    client.Send (message);
}

Try that.

over 4 years ago · Santiago Trujillo Report

0

You can set your options to "SecureSocketOptions.Auto" something like this

await client.ConnectAsync(mailService.Host, mailService.Port,   SecureSocketOptions.Auto);

MailKit will automatically decide to use SSL or TLS.

over 4 years ago · Santiago Trujillo Report

0

According to MailKit Doc

Connect(string host,int port,bool useSsl,CancellationToken cancellationToken = null)

The useSsl argument only controls whether or not the client makes an SSL-wrapped connection. In other words, even if the useSsl parameter is false, SSL/TLS may still be used if the mail server supports the STARTTLS extension.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!