def send(text, subject=None, toAdd=None, cc=None, log_file=None): mail_info = config.config_dic['mail_info'] sslPort = 465 server = mail_info.get('server') user = mail_info.get('user') passwd = mail_info.get('password') if not (server and user and passwd): print('Invalid login info, exit!') return mail = Mail(server, port=sslPort, username=user, password=passwd, use_tls=False, use_ssl=True, debug_level=None) msg = Message(subject) msg.fromaddr = (user, user) msg.to = toAdd if cc: msg.cc = cc if log_file: zip_path = '/tmp/build.log.zip' zip_file(log_file, zip_path) with open(zip_path, encoding='ISO-8859-1') as f: attachment = Attachment("build.log.zip", "application/octet-stream", f.read()) msg.attach(attachment) msg.body = text msg.charset = "utf-8" mail.send(msg)
def send_alarm_mail(ip_target, ping_loss): curl_dir = os.path.split(os.path.realpath(__file__))[0] db_file = os.path.join(curl_dir, "p_a_t.db") con = sqlite3.connect(db_file) cur = con.cursor() sql_select = "select * from smtp_server where active=1" cur.execute(sql_select) smtp_info = cur.fetchone() if smtp_info: mail = Mail(smtp_info[1], port=smtp_info[2], username=smtp_info[3], password=smtp_info[4], use_ssl=True, fromaddr=smtp_info[3]) msg = Message("[Alarm]{} loss {}%".format(ip_target, ping_loss)) receivers = [] for i in smtp_info[6].split(","): receivers.append(i) msg.to = receivers msg.body = "" with open("{}.txt".format(ip_target)) as f: for i in f.readlines(): msg.body += i mail.send(msg) print("Alarm mail send successful.Receivers are :{}".format(receivers)) else: print("There's no active SMTP server,can't send alarm mail.")
def send(text, subject=None, cc=None, toAdd=None, log_file=None): mail_info = config.config_dic['mail_info'] sslPort = 465 server = mail_info.get('server') user = mail_info.get('user') passwd = mail_info.get('password') if not (server and user and passwd): print('Invalid login info, exit!') return mail = Mail(server, port=sslPort, username=user, password=passwd, use_tls=False, use_ssl=True, debug_level=None) msg = Message(subject) msg.fromaddr = (user, user) msg.to = toAdd if cc: msg.cc = cc if log_file: with open(log_file) as f: attachment = Attachment("build.log", "text/plain", f.read()) msg.attach(attachment) msg.body = text msg.charset = "utf-8" mail.send(msg)
def send_email(): try: data = app.current_request.json_body # print(data) email = data["email"] password = data["password"] smtp_server = data["smtp_server"] smtp_port = data["smtp_port"] toAddress = data["toAddress"] fromAddress = data["fromAddress"] name = data["name"] subject = data["subject"] bodyPLAIN = data["bodyPLAIN"] bodyHTML = textile(bodyPLAIN) mail = Mail(host=smtp_server, port=smtp_port, username=email, password=password, use_ssl=True) msg = Message() msg.subject = subject msg.fromaddr = (name, fromAddress) msg.to = toAddress msg.body = bodyPLAIN msg.html = bodyHTML # msg.cc = "*****@*****.**" # msg.bcc = ["*****@*****.**", "*****@*****.**"] # msg.reply_to = "*****@*****.**" msg.date = int(round(time.time())) msg.charset = "utf-8" msg.extra_headers = {} msg.mail_options = [] msg.rcpt_options = [] # print(msg) # print(type(msg)) mail.send(msg) return Response(body={'sent': True}, status_code=200, headers=custom_headers) except Exception as error: # print("Send Emails Error") # print(error) return Response(body={'AppError': str(error)}, status_code=500, headers=custom_headers)
def createMail(self, name, comment, email): msg = Message() sub = 'Comment From dh314Blog ' msg.fromaddr = ('Đường Hạo', '*****@*****.**') msg.subject = sub contentE = 'Bạn nhận được một comments từ dh314Blog \n Từ: ' + str( name) + '\nEmail: ' + str(email) + '\nNội dung: ' + str(comment) msg.body = contentE msg.to = '*****@*****.**' return msg
def sendMail(to, subject, msgContext): pLog("Send Server Mail") config = ConfigParser.RawConfigParser() config.read('defaults.cfg') msg = Message(subject, fromaddr=config.get('SendAbuse', 'from'), to=to) if(to!=config.get('SendAbuse', 'from')): msg.bcc = config.get('SendAbuse', 'from') msg.body = msgContext msg.date = time.time() msg.charset = "utf-8" mail = Mail(config.get('SendAbuse', 'server'), port=config.get('SendAbuse', 'port'), username=config.get('SendAbuse', 'user'), password=config.get('SendAbuse', 'pass'),use_tls=False, use_ssl=False, debug_level=None) mail.send(msg)
def send_jobs(jobs): "Send an email notifying of current jobs" msg = Message( config['email']['subject'].format(n=len(jobs)), to=config['email_address'], ) msg.body = "Found {n} potential jobs:\n\n" for idx, job in enumerate(jobs): idx += 1 msg.body += "{}. {}\n\n\n".format(idx, job.to_string()) MAIL.send(msg)
def sendMail(to, subject, msgContext): pLog("Send Server Mail") config = ConfigParser.RawConfigParser() config.read('defaults.cfg') msg = Message(subject, fromaddr=config.get('SendAbuse', 'from'), to=to) if (to != config.get('SendAbuse', 'from')): msg.bcc = config.get('SendAbuse', 'from') msg.body = msgContext msg.date = time.time() msg.charset = "utf-8" mail = Mail(config.get('SendAbuse', 'server'), port=config.get('SendAbuse', 'port'), username=config.get('SendAbuse', 'user'), password=config.get('SendAbuse', 'pass'), use_tls=False, use_ssl=False, debug_level=None) mail.send(msg)
pwrd = os.environ['GMAIL_PASS'] if __name__ == "__main__": with Imbox(imap, username=user, password=pwrd, ssl=True, ssl_context=None, starttls=False) as imbox: drafts = imbox.messages(folder="[Gmail]/Drafts") todays_mail = [] for uid, msg in drafts: if 'schedmail' in msg.subject.lower(): date = msg.subject.lower().split(':')[1] today = pendulum.now().date().isoformat() subject_date = pendulum.parse(date).date().isoformat() if subject_date == today: todays_mail.append(msg) mail = Mail('smtp.gmail.com', port=587, username=user, password=pwrd, use_tls=True) for i in todays_mail: msg = Message(i.subject.split(':')[-1]) msg.fromaddr = (i.sent_from[0]['name'], i.sent_from[0]['email']) msg.to = [j['email'] for j in i.sent_to] msg.cc = [j['email'] for j in i.cc] msg.bcc = [j['email'] for j in i.bcc] msg.body = i.body['plain'][0] msg.html = i.body['html'][0] msg.charset = 'utf-8' mail.send(msg)
SMTP_HOST = 'smtp.example.com' SMTP_USER = '******' SMTP_PASS = '******' SMTP_ADDRESS = '*****@*****.**' mail = Mail(host=SMTP_HOST, username=SMTP_USER, password=SMTP_PASS, fromaddr=SMTP_ADDRESS) msg01 = Message("Hello01", to="*****@*****.**", body="hello world") msg02 = Message("Hello02", to="*****@*****.**") msg02.fromaddr = ('no-reply', '*****@*****.**') msg02.body = "hello world!" msg03 = Message("Hello03", to="*****@*****.**") msg03.fromaddr = (u'请勿回复', '*****@*****.**') msg03.body = u"你好世界" # Chinese :) msg03.html = u"<b>你好世界</b>" msg04 = Message("Hello04", body="Hello world 04") msg04.to = "*****@*****.**" msg04.cc = ["*****@*****.**", "cc02@example"] msg04.bcc = ["*****@*****.**"] msg05 = Message("Hello05", to="*****@*****.**", body="Hello world 05") with open("../docs/_static/sender.png") as f: msg05.attach_attachment("sender.png", "image/png", f.read())
# in email_server_config.txt, you enter your email information in this format: smtp.example.com,25,username,password with open('./email_server_config.txt','r') as f: config_content=[] for line in f.readlines(): config_content=line.split(",") smtp_server=config_content[0] smtp_server_port=config_content[1] smtp_server_username=config_content[2] smtp_server_password=config_content[3] mail=Mail(smtp_server,port=smtp_server_port,username=smtp_server_username,password=smtp_server_password,\ use_tls=False,use_ssl=False,debug_level=None) from sender import Message with open('./to_email_list.txt','r') as f: for line in f.readlines(): msg=Message("email subject",fromaddr=("burness","*****@*****.**"),to=line) msg.body = "this is a msg plain text body" msg.date = time.time() msg.charset = "utf-8" msg.extra_headers = {} msg.mail_options = [] msg.rcpt_options = [] from sender import Attachment with open("to_email_list.txt") as f: attachment=Attachment("to_email_list.txt","text/txt",f.read()) msg.attach(attachment) mail.send(msg) print 'To check in your email that ensure it is ok'
msg = Message(fromaddr=("Adam Elchert", "*****@*****.**")) updateFile() logger.debug('Running UpdateFile()') if os.path.getsize('fileOutput.txt') != 0: # attachment with open('fileOutput.txt') as fileOutput: attachment = fileOutput.read() fileOutput.close() # update message object msg.fromaddr = ("*****@*****.**") msg.body= '{}'.format(attachment) msg.to = ('*****@*****.**') msg.subject=('Tweets from {}'.format(strftime('%B %d'))) mail.send(msg) logger.info('Sent Email') logger.debug('Debug: %s', [msg]) os.remove('fileOutput.txt') logger.debug('fielOutput.txt removed') else: logger.debug('No tweet updates - No mail sent') os.remove('fileOutput.txt') logger.debug('fileOutput.txt removed') sys.exit()
#!/usr/bin/env python3 # Before begin you need to change Gmail settings: # 1. Turn off 2-step verification # 2. Enable: Allow less secure apps from sender import Mail, Message mail = Mail("smtp.gmail.com", port=587, username="******", password="******", use_tls=True, use_ssl=False, debug_level=None) mail.fromaddr = ("Sender Name", "*****@*****.**") msg = Message("msg subject") msg.fromaddr = ("Sender Name", "*****@*****.**") msg.to = "*****@*****.**" msg.body = "this is a msg plain text body" msg.html = "<b>this is a msg text body</b>" msg.reply_to = "*****@*****.**" msg.charset = "utf-8" msg.extra_headers = {} msg.mail_options = [] msg.rcpt_options = [] # Send message mail.send(msg)
SMTP_HOST = 'smtp.example.com' SMTP_USER = '******' SMTP_PASS = '******' SMTP_ADDRESS = '*****@*****.**' mail = Mail(host=SMTP_HOST, username=SMTP_USER, password=SMTP_PASS, fromaddr=SMTP_ADDRESS) msg01 = Message("Hello01", to="*****@*****.**", body="hello world") msg02 = Message("Hello02", to="*****@*****.**") msg02.fromaddr = ('no-reply', '*****@*****.**') msg02.body = "hello world!" msg03 = Message("Hello03", to="*****@*****.**") msg03.fromaddr = (u'请勿回复', '*****@*****.**') msg03.body = u"你好世界" # Chinese :) msg03.html = u"<b>你好世界</b>" msg04 = Message("Hello04", body="Hello world 04") msg04.to = "*****@*****.**" msg04.cc = ["*****@*****.**", "cc02@example"] msg04.bcc = ["*****@*****.**"] msg05 = Message("Hello05", to="*****@*****.**", body="Hello world 05")
#SETTINGS smtp_hostname = "" smtp_port = 25 smtp_username = "" smtp_password = "" smtp_security = "SSL" #END SETTINGS input = sys.stdin.read() text = mime.from_string(input) msg = Message(text.headers['subject']) msg.fromaddr = text.headers['from'] msg.to = text.headers['to'] msg.body = text.body msg.date = time.time() msg.charset = "utf-8" #Check SSL or TLS smtp_ssl_use = False smtp_tls_use = False if smtp_security == "SSL": smtp_ssl_use = True elif smtp_security == "TLS": smtp_tls_use = True else: smtp_ssl_use = False smtp_tls_use = False mail = Mail(smtp_hostname, port=smtp_port, username=smtp_username, password=smtp_password, use_tls=smtp_tls_use, use_ssl=smtp_ssl_use, debug_level = None)