问题
I'm using pyramid_exclog to log exceptions and send those exceptions as email. I'm using Amazon aws SMTP to send emails. But I'm getting the following error:
SMTPAuthenticationError: (530, 'Must issue a STARTTLS command first')
Here's the code I use:
[handler_email_exc_handler]
class = handlers.SMTPHandler
args = (('email-smtp.us-east-1.amazonaws.com', 587), 'no-reply@company.com', ['me@company.com'], 'Company Exception' ,('<username>','<user_key>'),None)
level = ERROR
formatter = exc_formatter
As far as I know, there's nothing wrong with the aws credentials, since I used them to send mails via Thunderbird.
回答1:
It isn't the credentials, at least not according to this error message. You are trying to speak SMTP to SES without using TLS -- you are trying to authenticate yourself over an unencrypted connection. This isn't secure, as it could result in the compromise of your credentials, so it isn't supported.
The Amazon SES SMTP endpoint requires that all connections be encrypted using Transport Layer Security (TLS). (Note that TLS is often referred to by the name of its predecessor protocol, SSL.) Amazon SES supports two mechanisms for establishing a TLS-encrypted connection: STARTTLS and TLS Wrapper. Check the documentation for your software to determine whether it supports STARTTLS, TLS Wrapper, or both.
If your software does not support STARTTLS or TLS Wrapper, you can use the open source stunnel program to set up an encrypted connection (called a "secure tunnel"), then use the secure tunnel to connect to the Amazon SES SMTP endpoint.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-connect.html
I am not a Python person, but a quick check of the Google machine suggests this:
To specify the use of a secure protocol (TLS), pass in a tuple to the secure argument. This will only be used when authentication credentials are supplied. The tuple should be either an empty tuple, or a single-value tuple with the name of a keyfile, or a 2-value tuple with the names of the keyfile and certificate file. (This tuple is passed to the smtplib.SMTP.starttls() method.)
https://docs.python.org/2/library/logging.handlers.html
Aha, it even mentions "starttls."
If I've found the right reference, perhaps your last argument should be ()
instead of None
, since you shouldn't need a keyfile or certificate file.
来源:https://stackoverflow.com/questions/31872336/pyramid-exclog-smtpauthenticationerror-530-must-issue-a-starttls-command-f