is there a command or fuction in python that deals with email?
like:
email(ibmceo@ibm.com, 'Hello, my name is Bill. How are you doing at IBM?', email.cc(),attach("C:\123321.txt")) :D
is there a command or fuction in python that deals with email?
like:
email(ibmceo@ibm.com, 'Hello, my name is Bill. How are you doing at IBM?', email.cc(),attach("C:\123321.txt")) :D
Short answer: there is no single built-in email(...) function. Python’s standard library gives two pieces you combine: the email package to build messages and smtplib to send them. As suggested, use the SMTP client for delivery; and pointed to helpful example pages for composition. For modern Python the EmailMessage API makes To/Cc/attachments straightforward.
Example (replace placeholders with your server, addresses and credentials):
from email.message import EmailMessage
import smtplib
import mimetypes
from pathlib import Path
msg = EmailMessage()
msg['Subject'] = 'Hello from Python'
msg['From'] = 'sender@example.com'
msg['To'] = 'recipient@example.com'
msg['Cc'] = 'cc@example.com'
msg.set_content('Hello — this is a plain-text body.')
p = Path('attachment.txt')
ctype, _ = mimetypes.guess_type(str(p))
if ctype is None:
ctype = 'application/octet-stream'
maintype, subtype = ctype.split('/', 1)
with p.open('rb') as f:
msg.add_attachment(f.read(), maintype=maintype, subtype=subtype, filename=p.name)
with smtplib.SMTP('smtp.example.com', 587) as smtp:
smtp.starttls()
smtp.login('username', 'password')
smtp.send_message(msg) Practical tips: send_message will derive recipients from your To/Cc/Bcc headers, but you can pass explicit addresses if you prefer. Use port 587 + STARTTLS or port 465 + SMTP_SSL depending on the provider. Do not hard-code credentials—use environment variables or a secrets store. For Gmail and many providers you now need an app password or OAuth2 (not the legacy “less secure apps” option). For testing, send to a local/debug SMTP server or a sandbox service rather than real recipients. Common failures are authentication errors, wrong server/port, and firewall/DNS issues—inspect exception messages and enable verbose SMTP debugging where needed.
Jump to Post— programmersbook 17Look into http://docs.python.org/library/smtplib.html ;)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.