[sylpheed:36807] Re: using a python program to send e-mail with sylpheed
Ranjan Maitra
maitra at email.com
Sat May 4 01:06:26 JST 2019
On Fri, 3 May 2019 08:44:32 -0500 Rich Coe <rcoe at wi.rr.com> wrote:
> On Thu, 2 May 2019 01:07:50 -0500
> Ranjan Maitra <maitra at email.com> wrote:
> > Hi,
> >
> > Anyone have a suggestion on how to make a send-mail facillity written in python can work here?
>
> You are bypassing the existing, working smtp client in sylpheed with another,
> exactly similar, smtp client which you have made in python.
>
> There is nothing in the python script which sylpheed does not do already.
> The script does prove that with the correct authorization, you are able to
> send smtp mail at work.
>
> If you added your smtp and authorization configuration to sylpheed and it
> does not work, maybe report what went wrong. Looking at the 'log' from the
> tools menu might be useful.
>
> R
I wanted to mention that I need to use an external sendmail application because it can only be accessed using a separate script (which is easiest to write in python, but that is not important). So it is important to use an external sendmail.
I submitted the python script to get an idea of how to use an external sendmail application. I figured that it would be easier to understand first with a simple example and then proceed from there for me. Besides, the exact way of sending e-mail is too specific for it to be of any use to others.
So that it does not get lost in the earlier e-mails, here is my question:
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