s = cls(timeout = timeout, local_hostname = localhost)
s.set_debuglevel(verbose)
if port < 0:
port = None if encryption == 'TLS' else 465
s.connect(relay, port)
if encryption == 'TLS':
s.starttls()
s.ehlo()
if username is not None and password is not None:
if encryption == 'SSL':
s.sock = s.file.sslobj
s.login(username, password)
s.sendmail(from_, to, msg)
return s.quit()
def option_parser():
try:
OptionParser = OptionParser
import calibre.utils.config
OptionParser
except ImportError:
OptionParser = OptionParser
import optparse
import textwrap
parser = OptionParser(textwrap.dedent(' %prog [options] [from to text]\n\n Send mail using the SMTP protocol. %prog has two modes of operation. In the\n compose mode you specify from to and text and these are used to build and\n send an email message. In the filter mode, %prog reads a complete email\n message from STDIN and sends it.\n\n text is the body of the email message.\n If text is not specified, a complete email message is read from STDIN.\n from is the email address of the sender and to is the email address\n of the recipient. When a complete email is read from STDIN, from and to\n are only used in the SMTP negotiation, the message headers are not modified.\n '))
c = parser.add_option_group('COMPOSE MAIL', 'Options to compose an email. Ignored if text is not specified').add_option
c('-a', '--attachment', help = 'File to attach to the email')
c('-s', '--subject', help = 'Subject of the email')
parser.add_option('-l', '--localhost', help = 'Host name of localhost. Used when connecting to SMTP server.')
r = parser.add_option_group('SMTP RELAY', 'Options to use an SMTP relay server to send mail. calibre will try to send the email directly unless --relay is specified.').add_option
r('-r', '--relay', help = 'An SMTP relay server to use to send mail.')
r('-p', '--port', default = -1, help = 'Port to connect to on relay server. Default is to use 465 if encryption method is SSL and 25 otherwise.')
r('-u', '--username', help = 'Username for relay')
r('-p', '--password', help = 'Password for relay')
'SSL'], help = 'Encryption method to use when connecting to relay. Choices are TLS and SSL. Default is TLS.')
parser.add_option('-o', '--outbox', help = 'Path to maildir folder to store failed email messages in.')
parser.add_option('-f', '--fork', default = False, action = 'store_true', help = 'Fork and deliver message in background. If you use this option, you should also use --outbox to handle delivery failures.')
parser.add_option('-t', '--timeout', help = 'Timeout for connection')
parser.add_option('-v', '--verbose', default = 0, action = 'count', help = 'Be more verbose')