[sylpheed:36803] using a python program to send e-mail with sylpheed

Ranjan Maitra maitra at email.com
Sun Apr 28 08:43:52 JST 2019


Hi,

I am trying to figure out how to use sylpheed with sending e-mail in python (which is the only way that I can send e-mail from work).

I have the following python script (which is deliberately simple at this stage for me to simply understand what to do).

#!/usr/bin/python

import smtplib
import email.utils
from email.mime.text import MIMEText
import getpass

# Prompt the user for connection info
to_email = input('Recipient: ')
servername = input('Mail server name: ')
serverport = input('Server port: ')
if serverport:
    serverport = int(serverport)
else:
    serverport = 25
use_tls = input('Use TLS? (yes/no): ').lower()
username = input('Mail username: ')
password = getpass.getpass("%s's password: " % username)

# Create the message
msg = MIMEText('Test message from PyMOTW.')
msg.set_unixfrom('author')
msg['To'] = email.utils.formataddr(('Recipient', to_email))
msg['From'] = email.utils.formataddr(('Author', username))
msg['Subject'] = 'Test from PyMOTW'

if use_tls == 'yes':
    print('starting with a secure connection')
    server = smtplib.SMTP_SSL(servername, serverport)
else:
    print('starting with an insecure connection')
    server = smtplib.SMTP(servername, serverport)
try:
    server.set_debuglevel(True)

    # identify ourselves, prompting server for supported features
    server.ehlo()

    # If we can encrypt this session, do it
    if server.has_extn('STARTTLS'):
        print('(starting TLS)')
        server.starttls()
        server.ehlo()  # reidentify ourselves over TLS connection
    else:
        print('(no STARTTLS)')

    if server.has_extn('AUTH'):
        print('(logging in)')
        server.login(username, password)
    else:
        print('(no AUTH)')

    server.sendmail(username,
                    to_email,
                    msg.as_string())
finally:
    server.quit()



I can get it to work with my mail server, etc from the command line when I send the e-mail in the following way (note that the program is called mailsend.py and is an executable).

./mailsend

Then, I am asked the following:
Recipient e-mail
Server address
Port
Whether TLS or not
Sender e-mail
Sender password

to which stdin output is required and upon correct submission, the e-mail is successfully sent.

My question is how do I get the sylpheed mailer to submit these stdin output so that the script can take over from here and deliver.

I am happy to provide more information.

Many thanks in advance for any help, and I am sorry if this is a trivial question. I am not very familiar with the sending side of things and I still want to be able to use sylpheed.

Best wishes,
Ranjan




More information about the Sylpheed mailing list