Every line of 'python send email outlook' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
430 def send_email(from_address, to_address, subject, body): 431 msg = email.mime.text.MIMEText(body) 432 msg['Subject'] = subject 433 msg['From'] = from_address 434 msg['To'] = to_address 435 # print "from_address %r" % from_address 436 # print "to_address %r" % to_address 437 # print "msg.as_string():\n%s" % msg.as_string() 438 s = smtplib.SMTP() 439 s.connect() 440 s.sendmail(from_address, [to_address], msg.as_string()) 441 s.quit()
7 def send_mail(sender: str, recipient: str, subject: str, body: str) -> None: 8 msg = email.mime.text.MIMEText(body) 9 msg["Subject"] = subject 10 msg["From"] = sender 11 msg["To"] = recipient 12 13 smtp = smtplib.SMTP( 14 config.config["smtp"]["host"], int(config.config["smtp"]["port"]) 15 ) 16 smtp.login(config.config["smtp"]["user"], config.config["smtp"]["pass"]) 17 smtp.send_message(msg) 18 smtp.quit()
24 def send(email_from, email_to, subject, body, server=None, port=-1, username="", password="", secure=False, email_type='html'): 25 if not server: 26 server = DEFAULT_SERVER 27 if port < 0: 28 port = DEFAULT_PORT 29 msg = MIMEMultipart() 30 msg['From'] = email_from 31 msg['To'] = email_to 32 msg['Subject'] = subject 33 msg['Date'] = formatdate(localtime=True) 34 msg.attach(MIMEText(body, email_type)) 35 try: 36 server = smtplib.SMTP(server, port) 37 if secure: 38 server.ehlo() 39 server.starttls() 40 server.ehlo() 41 if username: 42 server.login(username, password) 43 text = msg.as_string() 44 senders = server.sendmail(email_from, email_to, text) 45 server.quit() 46 return senders 47 except Exception as e: 48 Log.Debug("Error in sendEMail: " + e.message) 49 Log.Error(str(traceback.format_exc())) # raise last error 50 return True
41 def send(self, email, text): 42 """send an email.""" 43 print("Sent an email to %s, text=%s." % (email, text))
43 def sendMessage(self, subject, body): 44 """Alert on the set of alerts provided.""" 45 emails=( 46 'dustin@spy.net', 47 'noelani@spy.net', 48 'dsallings@tmomail.net',) 49 sender='dustin+temperature@spy.net' 50 51 # Construct a MIME message. 52 msg=MIMEText(body) 53 msg['From'] = sender 54 msg['Subject'] = subject 55 56 # Send to each recipient 57 for addr in emails: 58 msg['To'] = addr 59 # Send the mail 60 server = smtplib.SMTP('mail') 61 server.sendmail(sender, addr, msg.as_string()) 62 server.quit()
10 def send_email(attachment): 11 12 sender = os.environ.get('SENDER', None) 13 gmail_password = os.environ.get('GMAIL_PASSWORD', None) 14 recipients = ['douglasnavarro94@gmail.com'] 15 16 outer = MIMEMultipart() 17 outer['Subject'] = 'Debug scraper' 18 outer['To'] = COMMASPACE.join(recipients) 19 outer['From'] = sender 20 outer.preamble = 'You will not see this in a MIME-aware mail reader.\n' 21 22 msg = MIMEBase('application', "octet-stream") 23 msg.set_payload(attachment) 24 encoders.encode_base64(msg) 25 msg.add_header('Content-Disposition', 'attachment', 26 filename='viaquatro.html') 27 outer.attach(msg) 28 29 composed = outer.as_string() 30 31 with smtplib.SMTP('smtp.gmail.com', 587) as s: 32 s.ehlo() 33 s.starttls() 34 s.ehlo() 35 s.login(sender, gmail_password) 36 s.sendmail(sender, recipients, composed) 37 s.close() 38 print("Email sent!")
30 def send(self, to, subject, body, cc=None, attachs=()): 31 if attachs: 32 msg = MIMEMultipart() 33 else: 34 msg = MIMENonMultipart('text', 'plain') 35 msg['From'] = self.mailfrom 36 msg['To'] = COMMASPACE.join(to) 37 msg['Date'] = formatdate(localtime=True) 38 msg['Subject'] = subject 39 rcpts = to[:] 40 if cc: 41 rcpts.extend(cc) 42 msg['Cc'] = COMMASPACE.join(cc) 43 44 if attachs: 45 msg.attach(MIMEText(body)) 46 for attach_name, mimetype, f in attachs: 47 part = MIMEBase(*mimetype.split('/')) 48 part.set_payload(f.read()) 49 Encoders.encode_base64(part) 50 part.add_header('Content-Disposition', 'attachment; filename="%s"' % attach_name) 51 msg.attach(part) 52 else: 53 msg.set_payload(body) 54 55 # FIXME --------------------------------------------------------------------- 56 # There seems to be a problem with sending emails using deferreds when 57 # the last thing left to do is sending the mail, cause the engine stops 58 # the reactor and the email don't get send. we need to fix this. until 59 # then, we'll revert to use Python standard (IO-blocking) smtplib. 60 61 #dfd = self._sendmail(self.smtphost, self.mailfrom, rcpts, msg.as_string()) 62 #dfd.addCallbacks(self._sent_ok, self._sent_failed, 63 # callbackArgs=[to, cc, subject, len(attachs)], 64 # errbackArgs=[to, cc, subject, len(attachs)]) 65 import smtplib 66 smtp = smtplib.SMTP(self.smtphost) 67 smtp.sendmail(self.mailfrom, rcpts, msg.as_string()) 68 log.msg('Mail sent: To=%s Cc=%s Subject="%s"' % (to, cc, subject)) 69 smtp.close()
50 def sendmail(send_from, send_to, subject, text, files=None, cc=None): 51 assert isinstance(send_to, list) 52 53 msg = MIMEMultipart() 54 msg['From'] = Header(send_from, 'utf-8') 55 msg['To'] = ", ".join(send_to) 56 msg['Date'] = formatdate(localtime=True) 57 msg['Message-ID'] = make_msgid() # Returns a string suitable for RFC 2822 compliant Message-ID. 58 msg['Subject'] = Header(subject, 'utf-8') 59 msg.attach(MIMEText(text, 'plain', 'utf-8')) # MIMEText(html,'html','utf8') 60 61 if cc is not None: 62 msg['CC'] = cc 63 64 for attachment in files or []: 65 attachment = to_unicode_or_bust(attachment) # convert str to unicode 66 if os.path.exists(attachment): # Unicode is required 67 filename = os.path.basename(attachment) 68 with open(attachment, "rb") as fd: # Unicode is required 69 part = MIMEApplication( 70 fd.read(), 71 Name=filename, 72 ) 73 part['Content-Disposition'] = 'attachment; filename="%s"' % filename.encode("utf-8") 74 msg.attach(part) 75 76 smtp = smtplib.SMTP() 77 smtp.connect(EMAIL_HOST, EMAIL_PORT) 78 smtp.starttls() 79 smtp.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD) 80 smtp.sendmail(send_from, send_to, msg.as_string()) 81 smtp.close()
30 def sendmail(recipients, sender='', msg='', subject='[No Subject]'): 31 """send an html email as multipart with attachments and all""" 32 from webnotes.utils.email_lib.smtp import get_email 33 get_email(recipients, sender, msg, subject).send()
38 def _send_mail(subject, body, from_email, recipient_list, 39 fail_silently=False, html=None): 40 msg = EmailMultiAlternatives(subject, body, from_email, recipient_list) 41 if html: 42 msg.attach_alternative(html, "text/html") 43 msg.send(fail_silently)