def test_email_settings(self, to): opts = smtp_prefs().parse() from calibre.utils.smtp import sendmail, create_mail buf = cStringIO.StringIO() debug_out = partial(prints, file=buf) oout, oerr = sys.stdout, sys.stderr sys.stdout = sys.stderr = buf tb = None try: msg = create_mail(opts.from_, to, 'Test mail from calibre', 'Test mail from calibre') sendmail(msg, from_=opts.from_, to=[to], verbose=3, timeout=30, relay=opts.relay_host, username=opts.relay_username, debug_output=debug_out, password=unhexlify(opts.relay_password).decode('utf-8'), encryption=opts.encryption, port=opts.relay_port) except: import traceback tb = traceback.format_exc() tb += '\n\nLog:\n' + buf.getvalue() finally: sys.stdout, sys.stderr = oout, oerr return tb
def test_email_settings(self, to): opts = smtp_prefs().parse() from calibre.utils.smtp import sendmail, create_mail buf = cStringIO.StringIO() oout, oerr = sys.stdout, sys.stderr sys.stdout = sys.stderr = buf tb = None try: msg = create_mail(opts.from_, to, "Test mail from calibre", "Test mail from calibre") sendmail( msg, from_=opts.from_, to=[to], verbose=3, timeout=30, relay=opts.relay_host, username=opts.relay_username, password=unhexlify(opts.relay_password).decode("utf-8"), encryption=opts.encryption, port=opts.relay_port, ) except: import traceback tb = traceback.format_exc() tb += "\n\nLog:\n" + buf.getvalue() finally: sys.stdout, sys.stderr = oout, oerr return tb
def do_send_mail(self, book, mail_to, fmt, fpath): body = open(fpath).read() # read meta info author = authors_to_string( book['authors'] if book['authors'] else [_('Unknown')]) title = book['title'] if book['title'] else _("No Title") fname = u'%s - %s.%s' % (title, author, fmt) fname = ascii_filename(fname).replace('"', '_') # content type mt = guess_type('dummy.' + fmt)[0] if mt is None: mt = 'application/octet-stream' # send mail mail_from = '*****@*****.**' mail_subject = _('Book from Calibre: %(title)s') % vars() mail_body = _('We Send this book to your kindle.') status = msg = "" try: msg = create_mail(mail_from, mail_to, mail_subject, text=mail_body, attachment_data=body, attachment_type=mt, attachment_name=fname) sendmail(msg, from_=mail_from, to=[mail_to], timeout=30, username=tweaks['smtp_username'], password=tweaks['smtp_password']) status = "success" msg = _('Send to kindle success!! email: %(mail_to)s') % vars() except: import traceback cherrypy.log.error('Failed to generate cover:') cherrypy.log.error(traceback.format_exc()) status = "danger" msg = traceback.format_exc() messages.append({'status': status, 'msg': msg}) return
def test_email_settings(self, to): opts = smtp_prefs().parse() from calibre.utils.smtp import sendmail, create_mail buf = PolyglotBytesIO() debug_out = partial(prints, file=buf) oout, oerr = sys.stdout, sys.stderr sys.stdout = sys.stderr = buf tb = None try: msg = create_mail(opts.from_, to, 'Test mail from calibre', 'Test mail from calibre') sendmail(msg, from_=opts.from_, to=[to], verbose=3, timeout=30, relay=opts.relay_host, username=opts.relay_username, debug_output=debug_out, password=from_hex_unicode(opts.relay_password), encryption=opts.encryption, port=opts.relay_port) except: import traceback tb = traceback.format_exc() tb += '\n\nLog:\n' + buf.getvalue().decode('utf-8', 'replace') finally: sys.stdout, sys.stderr = oout, oerr return tb