def SendMail(server, sender, recipients, subject, text, attachments, password, ignore_missing): """Sends a plain text email with optional attachments. Args: server: The address of the SMTP server sender: The sender's email address recipients: The list of recipient emails addresses subject: The subject of the message text: The body of the message attachments: A list of file paths to attach password: The (optional) password to use when authenticating to the smtp server. """ # Create the e-mail message envelope = email.mime.multipart.MIMEMultipart() envelope["Subject"] = subject envelope["From"] = sender envelope["To"] = _COMMASPACE.join(recipients) envelope.preamble = "" for file_pattern in attachments: matching_paths = glob.glob(file_pattern) if not matching_paths and not ignore_missing: raise Exception("%s not found" % file_pattern) for file_path in matching_paths: envelope.attach(GetAttachment(file_path)) message = email.mime.text.MIMEText(text.encode("utf-8"), "plain", "UTF-8") envelope.attach(message) # Send the e-mail message smtp_client = smtplib.SMTP(server) smtp_client.starttls() if password: smtp_client.login(sender, password) smtp_client.sendmail(sender, recipients, envelope.as_string()) smtp_client.quit()
def send_mail(self, lines, severity, project, target, tolist): mail = email.mime.multipart.MIMEMultipart() mail["To"] = ", ".join(tolist) mail["From"] = self._mfrom mail["Date"] = format_date_time( calendar.timegm(datetime.utcnow().utctimetuple())) mail["Subject"] = self._subject.format(severity=severity, project=project, target=target) text = """ Hello, This is buildbot. This is a status notification for the job {project} / {target} The job has the status: {severity}. Please see the attached output log for details and take appropriate action.""".format(severity=severity, project=project, target=target) mime_text = email.mime.text.MIMEText(text.encode("utf-8"), _charset="utf-8") mail.attach(mime_text) mime_log = email.mime.text.MIMEText("\n".join(lines).encode("utf-8"), _charset="utf-8") mime_log.add_header("Content-Disposition", "attachment", filename="job.log") mail.attach(mime_log) self._sendconfig.send_mime_mail(mail, tolist)
def to_cset_out(text, lcset): # Convert text from unicode or lcset to output cset. ocset = Charset(lcset).get_output_charset() or lcset if isinstance(text, (bytes, bytearray)): return text.encode(ocset, 'replace') else: return text.decode(lcset, 'replace').encode(ocset, 'replace')
def send_mail(subject, text, recipients, sender, replyTo=None): assert isinstance(recipients, list) if not len(recipients): return # nothing to do # construct content msg = email.mime.text.MIMEText(text.encode('UTF-8'), 'plain', 'UTF-8') msg['Subject'] = subject msg['Date'] = email.utils.formatdate(localtime=True) msg['From'] = sender msg['To'] = ', '.join(recipients) if replyTo is not None: msg['Reply-To'] = replyTo # put into envelope and send s = smtplib.SMTP('localhost') s.sendmail(sender, recipients, msg.as_string()) s.quit()
def send_mail(subject, text, recipients, sender, replyTo = None): assert isinstance(recipients, list) if not len(recipients): return # nothing to do # construct content msg = email.mime.text.MIMEText(text.encode('UTF-8'), 'plain', 'UTF-8') msg['Subject'] = subject msg['Date'] = email.utils.formatdate(localtime=True) msg['From'] = sender msg['To'] = ', '.join(recipients) if replyTo is not None: msg['Reply-To'] = replyTo # put into envelope and send s = smtplib.SMTP('localhost') s.sendmail(sender, recipients, msg.as_string()) s.quit()
def send_mail(self, lines, severity, project, target, tolist): mail = email.mime.multipart.MIMEMultipart() mail["To"] = ", ".join(tolist) mail["From"] = self._mfrom mail["Date"] = format_date_time( calendar.timegm(datetime.utcnow().utctimetuple())) mail["Subject"] = self._subject.format( severity=severity, project=project, target=target) text = """ Hello, This is buildbot. This is a status notification for the job {project} / {target} The job has the status: {severity}. Please see the attached output log for details and take appropriate action.""".format( severity=severity, project=project, target=target) mime_text = email.mime.text.MIMEText( text.encode("utf-8"), _charset="utf-8") mail.attach(mime_text) mime_log = email.mime.text.MIMEText( "\n".join(lines).encode("utf-8"), _charset="utf-8") mime_log.add_header( "Content-Disposition", "attachment", filename="job.log") mail.attach(mime_log) self._sendconfig.send_mime_mail(mail, tolist)
def SendMail(server, sender, recipients, subject, text, attachments, password, ignore_missing): """Sends a plain text email with optional attachments. Args: server: The address of the SMTP server sender: The sender's email address recipients: The list of recipient emails addresses subject: The subject of the message text: The body of the message attachments: A list of file paths to attach password: The (optional) password to use when authenticating to the smtp server. """ # Create the e-mail message envelope = email.mime.multipart.MIMEMultipart() envelope['Subject'] = subject envelope['From'] = sender envelope['To'] = _COMMASPACE.join(recipients) envelope.preamble = '' for file_pattern in attachments: matching_paths = glob.glob(file_pattern) if not matching_paths and not ignore_missing: raise Exception('%s not found' % file_pattern) for file_path in matching_paths: envelope.attach(GetAttachment(file_path)) message = email.mime.text.MIMEText(text.encode('utf-8'), 'plain', 'UTF-8') envelope.attach(message) # Send the e-mail message smtp_client = smtplib.SMTP(server) smtp_client.starttls() if password: smtp_client.login(sender, password) smtp_client.sendmail(sender, recipients, envelope.as_string()) smtp_client.quit()
def append(self, text): text = text.replace('\n', '') self.story.append(text) text = text.encode('utf-8') print >> self.fd, text self.fd.flush()