Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to send data from a contact form to email using python. I've tried several ways that don't seem to work.

The data is from a random user, then the data should be forwarded to a specific email, not the same email receiving the message as I've seen most YouTubers do in their videos.

Kindly, someone help me to implement this.

What I have tried:

import smtplib                          
host='mail.mycompany.com'      
fromAddr='user@example.com'         
toAddr='info@mycompany.com'     
text= "This is a test of sending email from within Python."
server = smtplib.SMTP(host,25)
server.ehlo()
server.starttls()
server.sendmail(fromAddr, toAddr, text) 
server.quit()
Posted
Updated 24-Aug-21 5:47am
Comments
Wendelius 24-Aug-21 11:35am    
Do you get an error when running the code?

1 solution

Try using the preferred port number for SMTP: https://www.mailgun.com/blog/which-smtp-port-understanding-ports-25-465-587/[^].

You should also check any response codes to see whether your calls succeeded or not: smtplib — SMTP protocol client — Python 3.9.6 documentation[^].
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900