3

I'm coding a script to automatically send emails with Python but I don't receive any email on the receiver adresses (I'm sure the adresses are good I checked 100 times) whereas the code is executing successfully.

Also, I tried using TLS (port 587) and SSL (port 465) and both are executing withtout error but nothing is sent.

I highly suspect the problem to come from OVH because I succeeded using one of my gmail adresses.

Here is my code :

from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import smtplib, ssl

# smtp = smtplib.SMTP('ssl0.ovh.net',587)
context = ssl.create_default_context()
smtp = smtplib.SMTP_SSL('ssl0.ovh.net',465, context=context)
smtp.set_debuglevel(1)
smtp.ehlo()
# smtp.starttls()
smtp.login(my_address, my_password)

subject = 'Bonsoir'
text = "Bonjour"
msg = MIMEMultipart()
msg['Subject'] = subject
msg.attach(MIMEText(text))

to = [receiver_address1, receiver_address2]
smtp.sendmail(from_addr=my_address,
              to_addrs=to,
              msg=msg.as_string())
smtp.quit()

Here is the response I get :

send: 'ehlo [192.168.1.60]\r\n'
reply: b'250-OVH SMTP PROXY Hello\r\n'
reply: b'250-SIZE 104857600\r\n'
reply: b'250-ENHANCEDSTATUSCODES\r\n'
reply: b'250-AUTH LOGIN PLAIN\r\n'
reply: b'250-AUTH=LOGIN PLAIN\r\n'
reply: b'250 8BITMIME\r\n'
reply: retcode (250); Msg: b'OVH SMTP PROXY Hello\nSIZE 104857600\nENHANCEDSTATUSCODES\nAUTH LOGIN PLAIN\nAUTH=LOGIN PLAIN\n8BITMIME'
send: 'AUTH PLAIN XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==\r\n'
reply: b'235 2.7.0 Authentication successful\r\n'
reply: retcode (235); Msg: b'2.7.0 Authentication successful'
send: 'mail FROM:<my_address> size=310\r\n'
reply: b'250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: b'2.1.0 Ok'
send: 'rcpt TO:<receiver_address1>\r\n'
reply: b'250 2.1.5 Ok\r\n'
reply: retcode (250); Msg: b'2.1.5 Ok'
send: 'rcpt TO:<receiver_address2>\r\n'
reply: b'250 2.1.5 Ok\r\n'
reply: retcode (250); Msg: b'2.1.5 Ok'
send: 'data\r\n'
reply: b'354 End data with <CR><LF>.<CR><LF>\r\n'
reply: retcode (354); Msg: b'End data with <CR><LF>.<CR><LF>'
data: (354, b'End data with <CR><LF>.<CR><LF>')
send: b'Content-Type: multipart/mixed; boundary="===============7340917115572025885=="\r\nMIME-Version: 1.0\r\nSubject: Bonsoir\r\n\r\n--===============7340917115572025885==\r\nContent-Type: text/plain; charset="us-ascii"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 7bit\r\n\r\nBonjour\r\n--===============7340917115572025885==--\r\n.\r\n'
reply: b'250 2.0.0 Ok: queued as 2B72E2803141D\r\n'
reply: retcode (250); Msg: b'2.0.0 Ok: queued as 2B72E2803141D'
data: (250, b'2.0.0 Ok: queued as 2B72E2803141D')
send: 'quit\r\n'
reply: b'221 XXXX.com Service closing transmission channel\r\n'
reply: retcode (221); Msg: b'XXXXX.com Service closing transmission channel'

I tried as well to go on OVH website and apparently I'm able to send automated emails.

Thanks in advance ! :)

bilbozen
  • 31
  • 1
  • Short addendum: this works (tested on port 587), but sometimes there are very long delays before you actually get the email, and these can be seen related to graylist behavior of the client email server; in case you suspect such behavior, test with a client on services like https://10minutemail.com/ – P Marecki Jul 28 '22 at 07:34

1 Answers1

0

Please use this it will work:

subject = 'Bonsoir'
text = "Bonjour"
msg = MIMEMultipart()
msg["From"] = "no-reply@*********.com"
msg["To"] = "contact@*********.com"
msg['Subject'] = subject
msg.attach(MIMEText(text))

to = ['contact@**********.com']
smtp.sendmail(my_address,
              to,
             msg.as_string())
Mohamed Hamzaoui
  • 325
  • 4
  • 15
  • Why? How? How is your code different from the original code? Also, the OP included a successful transmission log, so their code is working. How would your code address any server-side issues that could prevent the email from getting delivered? Code dump answers are rarely helpful... see [answer]. – Robert Aug 02 '23 at 14:24
  • First, do you tested it? Is it working for you? – Mohamed Hamzaoui Aug 03 '23 at 15:21