Email verzenden met Python
In sommige scripts waarbij je informatie wilt delen met anderen is het handig om informatie te versturen via email. Daarom is het erg handig dat email verzenden met python met een eenvoudige script goed te doen is. Email verzenden met python heeft eigenlijk alleen een stukje script wat werkt nodig.
Daarom een stukje script wat prima zou moeten functioneren. Zoals je ziet moet je natuurlijk wel even wat essentiele informatie invoeren om het versturen van mail mogelijk te maken. Dit heeft te maken met de uitgaande mailserver van je email provider. Daarnaast heeft elk mailadres een wachtwoord.
import email, ssl, smtplib
onderwerp = "Het onderwerp van je mail"
emailtekst = "Tekst wat je wilt hebben in de mail zelf"
ontvanger_email = doel@mailadres.nl
port = 465 #poort voor de uitgaande mailserver
smtp_server = "smtp server van de mail provider"
verstuur_email = "jou@mailadres.nl"
wachtwoord = "het wachtwoord van de mail account"
tekst = f'Subject: {onderwerp}\n\n{emailtekst}'
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(verstuur_email, wachtwoord)
server.sendmail(verstuur_email, ontvanger_email, tekst)
Reacties
Email verzenden met Python — Geen reacties
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>