import smtplib smtp_server = "smtp.example.com" smtp_port = 587 smtp_conn = smtplib.SMTP(smtp_server, smtp_port)
import smtplib smtp_server = "smtp.example.com" smtp_port = 587 smtp_username = "user@example.com" smtp_password = "password" smtp_conn = smtplib.SMTP(smtp_server, smtp_port) smtp_conn.login(smtp_username, smtp_password)
import smtplib from email.mime.text import MIMEText sender = "sender@example.com" receivers = ["receiver1@example.com", "receiver2@example.com"] msg = MIMEText("This is a test email.") msg['Subject'] = "Test Email" msg['From'] = sender msg['To'] = ",".join(receivers) smtp_server = "smtp.example.com" smtp_port = 587 smtp_conn = smtplib.SMTP(smtp_server, smtp_port) smtp_conn.sendmail(sender, receivers, msg.as_string())
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication sender = "sender@example.com" receivers = ["receiver1@example.com", "receiver2@example.com"] msg = MIMEMultipart() msg['Subject'] = "Test Email" msg['From'] = sender msg['To'] = ",".join(receivers) text = MIMEText("This is a test email.") msg.attach(text) pdf_file = open("test.pdf", "rb").read() pdf_part = MIMEApplication(pdf_file, Name="test.pdf") pdf_part['Content-Disposition'] = 'attachment; filename="test.pdf"' msg.attach(pdf_part) smtp_server = "smtp.example.com" smtp_port = 587 smtp_conn = smtplib.SMTP(smtp_server, smtp_port) smtp_conn.sendmail(sender, receivers, msg.as_string())
标签: 云主机