def settingsMenu(): clear() print "Settings:" copySettingsOptions = settingsOptions.copy() # colletct options optionsList = [] optionsList.append(newOption("Builtin recipes folder", settings.calibreFolder, settings.setCalibreFolder)) optionsList.append(newOption("Export format", settings.format, settings.setFormat)) optionsList.append(newOption("Mail from", settings.mailFrom, settings.setMailFrom)) optionsList.append(newOption("Mail To", settings.mailTo, settings.setMailTo)) if settings.useSmtp(): print "Using SMPT" copySettingsOptions["s"] = {"name": "Use sendmail", "function": sendmailSettings} optionsList.append(newOption("Smtp server", settings.smtpServer["address"], settings.setSmtpServerAdress)) if "port" in settings.smtpServer: optionsList.append(newOption("Smtp port", settings.smtpServer["port"], settings.setSmtpServerPort)) if "security" in settings.smtpServer: optionsList.append(newOption("Smtp security", settings.smtpServer["security"], settings.setSmtpServerSecurity)) if "login" in settings.smtpServer: optionsList.append(newOption("Smtp login", settings.smtpServer["login"], settings.setSmtpLogin)) if "password" in settings.smtpServer: encodedPw = "*" * len(settings.smtpServer["password"]) optionsList.append(newOption("Smtp password", encodedPw, settings.setSmtpPassword)) else: print "Using sendmail" copySettingsOptions["s"] = {"name": "Use smtp server", "function": createDefaultSmtpSettings} # append the options to the menu for (x, option) in enumerate(optionsList, 1): copySettingsOptions[str(x)] = option print print "Options:" makeMenu(copySettingsOptions)
def sendMail(subject, text, *attachmentFilePaths): recipient = settings.mailTo sender = settings.mailFrom msg = MIMEMultipart('mixed') msg['From'] = sender msg['To'] = recipient msg['Subject'] = subject msg.attach(MIMEText(text)) print "Start sending mail:" print "Recipient: %s" % recipient print "Sender: %s" % sender print "Subject: %s" % subject print "Recipient: %s" % recipient for attachmentFilePath in attachmentFilePaths: msg.attach(getAttachment(attachmentFilePath)) if settings.useSmtp(): if "port" in settings.smtpServer: mailServer = smtplib.SMTP( settings.smtpServer["address"], settings.smtpServer["port"]) else: mailServer = smtplib.SMTP(settings.smtpServer["address"]) if "security" in settings.smtpServer: if settings.smtpServer["security"] == "starttls": # handle starttls gmailUser = settings.smtpServer["login"] gmailPassword = settings.smtpServer["password"] mailServer.ehlo() mailServer.starttls() mailServer.ehlo() mailServer.login(gmailUser, gmailPassword) else: print "Using sendmail" mailServer = smtplib.SMTP('localhost') print "Sending mail" mailServer.set_debuglevel(1) mailServer.sendmail(sender, recipient, msg.as_string()) mailServer.close()