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 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 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)
# 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'
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) mail.send(msg)