def data_data(self, msg): if isinstance(msg, str): msg = _fix_eols(msg).encode('ascii') q = _quote_periods(msg) if q[-2:] != bCRLF: q = q + bCRLF q = q + b"." + bCRLF self.send(q) (code, msg) = self.getreply() if self.debuglevel > 0: print("data:", (code, msg), file=stderr) return (code, msg)
def sendmail(self, from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]): yield self.ehlo_or_helo_if_needed() esmtp_opts = [] if isinstance(msg, str): msg = smtplib._fix_eols(msg).encode('ascii') if self.does_esmtp: if self.has_extn('size'): esmtp_opts.append("size=%d" % len(msg)) for option in mail_options: esmtp_opts.append(option) (code, resp) = yield self.mail(from_addr, esmtp_opts) if code != 250: if code == 421: self.close() else: yield self._rset() raise smtplib.SMTPSenderRefused(code, resp, from_addr) senderrs = {} if isinstance(to_addrs, str): to_addrs = [to_addrs] for each in to_addrs: (code, resp) = yield self.rcpt(each, rcpt_options) if (code != 250) and (code != 251): senderrs[each] = (code, resp) if code == 421: self.close() raise smtplib.SMTPRecipientsRefused(senderrs) if len(senderrs) == len(to_addrs): # the server refused all our recipients yield self._rset() raise smtplib.SMTPRecipientsRefused(senderrs) (code, resp) = yield self.data(msg) if code != 250: if code == 421: self.close() else: yield self._rset() raise smtplib.SMTPDataError(code, resp) #if we got here then somebody got our mail return senderrs
def data(self, msg): """SMTP 'DATA' command -- sends message data to server. """ (code, repl) = yield self.docmd(b"data") if code != 354: raise smtplib.SMTPDataError(code, repl) else: if isinstance(msg, str): msg = smtplib._fix_eols(msg).encode("ascii") q = smtplib._quote_periods(msg) if q[-2:] != CRLF: q = q + CRLF q = q + b"." + CRLF # self.send(q) yield self.send(q) (code, msg) = yield self.getreply() return (code, msg)
def data(self, msg): """SMTP 'DATA' command -- sends message data to server. """ (code, repl) = yield self.docmd(b"data") if code != 354: raise smtplib.SMTPDataError(code, repl) else: if isinstance(msg, str): msg = smtplib._fix_eols(msg).encode('ascii') q = smtplib._quote_periods(msg) if q[-2:] != CRLF: q = q + CRLF q = q + b"." + CRLF #self.send(q) yield self.send(q) (code, msg) = yield self.getreply() return (code, msg)
def sendmail(self, from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]): yield self.ehlo_or_helo_if_needed() esmtp_opts = [] if isinstance(msg, str): msg = smtplib._fix_eols(msg).encode("ascii") if self.does_esmtp: if self.has_extn("size"): esmtp_opts.append("size=%d" % len(msg)) for option in mail_options: esmtp_opts.append(option) (code, resp) = yield self.mail(from_addr, esmtp_opts) if code != 250: if code == 421: self.close() else: yield self._rset() raise smtplib.SMTPSenderRefused(code, resp, from_addr) senderrs = {} if isinstance(to_addrs, str): to_addrs = [to_addrs] for each in to_addrs: (code, resp) = yield self.rcpt(each, rcpt_options) if (code != 250) and (code != 251): senderrs[each] = (code, resp) if code == 421: self.close() raise smtplib.SMTPRecipientsRefused(senderrs) if len(senderrs) == len(to_addrs): # the server refused all our recipients yield self._rset() raise smtplib.SMTPRecipientsRefused(senderrs) (code, resp) = yield self.data(msg) if code != 250: if code == 421: self.close() else: yield self._rset() raise smtplib.SMTPDataError(code, resp) # if we got here then somebody got our mail return senderrs
def update_event(self, inp=-1): self.set_output_val(0, smtplib._fix_eols(self.input(0)))