jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.

Home Page:http://www.mimekit.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fun with AWS SES

DierkDroth opened this issue · comments

I was able to get MailKit (SMTP) running against AWS SES.

However, there is problem:

  • first test email on that connection is fine
  • second mail just a few seconds later fails with "451 4.4.2 Timeout waiting for data from client." error from AWS

I learnt from here that this is actually expected (!!!), since AWS just kills the connection after a some inactivity time (aparently just a few seconds).

Now, are you aware of a settings which I could try in the SmtpClient to extend that 'inactivity period'?

Here are traces on an actual case:
// open the connection
2023-06-11 17:56:49:705 Smtp.Connected: 'smtp://email-smtp.eu-west-1.amazonaws.com:587/?starttls=when-available'
2023-06-11 17:56:49:822 Smtp.S: 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-d-PFJZ5UQMO MPOOIZsZ18ictWi0fWIA
2023-06-11 17:56:49:826 Smtp.C: EHLO Unusual
2023-06-11 17:56:49:983 Smtp.S: 250-email-smtp.amazonaws.com
2023-06-11 17:56:49:983 Smtp.S: 250-8BITMIME
2023-06-11 17:56:49:983 Smtp.S: 250-STARTTLS
2023-06-11 17:56:49:983 Smtp.S: 250-AUTH PLAIN LOGIN
2023-06-11 17:56:49:983 Smtp.S: 250 Ok
2023-06-11 17:56:49:985 Smtp.C: STARTTLS
2023-06-11 17:56:50:042 Smtp.S: 220 Ready to start TLS
2023-06-11 17:56:50:236 Smtp.C: EHLO Unusual
2023-06-11 17:56:50:284 Smtp.S: 250-email-smtp.amazonaws.com
2023-06-11 17:56:50:285 Smtp.S: 250-8BITMIME
2023-06-11 17:56:50:285 Smtp.S: 250-STARTTLS
2023-06-11 17:56:50:285 Smtp.S: 250-AUTH PLAIN LOGIN
2023-06-11 17:56:50:285 Smtp.S: 250 Ok
2023-06-11 17:56:50:295 Smtp.C: AUTH PLAIN AEFLSUFSVUNWUzJST0tGSFhRSkY3AEJBUFV6ZzdxRVFhL1hjbHQ0RlowcjEwb092YUJ6ZXhiQWZlczRRYnN6cDUv
2023-06-11 17:56:50:367 Smtp.S: 235 Authentication successful.

// send first (test) email -> good
2023-06-11 17:56:50:397 Smtp.C: MAIL FROM: EMAIL
2023-06-11 17:56:50:461 Smtp.S: 250 Ok
2023-06-11 17:56:50:462 Smtp.C: RCPT TO: EMAIL
2023-06-11 17:56:50:533 Smtp.S: 250 Ok
2023-06-11 17:56:50:534 Smtp.C: DATA
2023-06-11 17:56:50:608 Smtp.S: 354 End data with .
2023-06-11 17:56:50:618 Smtp.C: From: EMAIL
2023-06-11 17:56:50:618 Smtp.C: Date: Sun, 11 Jun 2023 17:56:50 +0000
2023-06-11 17:56:50:618 Smtp.C: Subject: Starting 'dev' server
2023-06-11 17:56:50:618 Smtp.C: Message-Id: R8Z6PM1H6KU4.QP4UWWOKDJRG@unusual
2023-06-11 17:56:50:618 Smtp.C: To: EMAIL
2023-06-11 17:56:50:618 Smtp.C: MIME-Version: 1.0
2023-06-11 17:56:50:619 Smtp.C: Content-Type: multipart/mixed; boundary="=-epme7xwiP7dAkGlUAB9FtQ=="
2023-06-11 17:56:50:619 Smtp.C: --=-epme7xwiP7dAkGlUAB9FtQ==
2023-06-11 17:56:50:619 Smtp.C: Content-Type: text/html; charset=utf-8
2023-06-11 17:56:50:619 Smtp.C: --=-epme7xwiP7dAkGlUAB9FtQ==--
2023-06-11 17:56:50:619 Smtp.C: .
2023-06-11 17:56:50:913 Smtp.S: 250 Ok 01020188ab9a8474-122c4e86-d166-4b15-bb3c-88c7e15c1a7d-000000

// second mail just a few seconds later fails -> bad
2023-06-11 17:57:00:812 Smtp.C: MAIL FROM: EMAIL
2023-06-11 17:57:00:842 Smtp.S: 451 4.4.2 Timeout waiting for data from client.
2023-06-11 17:57:00:844 Smtp.C: RSET

Yikes, that's only 10s later...

You could call client.NoOp() a bunch in between maybe?

Thanks @jstedfast. I ran more tests and applied a .NoOp every 5 (!!) seconds ... which appears to address the issue for now.

Oh well, funny AWS ...