SEND_MAIL python script

This script allows to verify if your mail server can correctly send emails with attachments.

Create with the below code and add executable permissions.

#!/usr/bin/env python
import smtplib, os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders
from email.mime.text import MIMEText

emaillist=[''] # Receipient email addressmsg = MIMEMultipart('mixed')
msg['Subject'] = 'DATA EMAIL' # mail subject line
msg['From'] = '' # From email address
msg['To'] = ', '.join(emaillist)

part = MIMEBase('application', "octet-stream")

# Provide the path of the file to be attached in the mailpart.set_payload(open('/root/test.txt', "rb").read())

part.add_header('Content-Disposition', 'attachment; filename="test.txt"')

msg.add_header('To', msg['From'])
text = "TEST BODY" #Email body
part1 = MIMEText(text, 'plain')

# provide SMTP details of the host and its port numberserver = smtplib.SMTP("",587)
# If the host supports TLS then enable the below 2 lines of code
#MI mail server support it
server.ehlo() # <--
server.starttls() # <--
server.login("notifications", "*************") #Login to mail server credentials
server.sendmail(msg['From'], emaillist , msg.as_string())


Add your comment

E-Mail me when someone replies to this comment