Answer the question
In order to leave comments, you need to log in
Can I send emails from my local smtp?
I have a local smtp server on aiosmtpd, how can I make it send emails to other servers like gmail? How can I do this and where to look, tell me the documentation.
import asyncio
import logging
from aiosmtpd.controller import Controller
from aiosmtpd.handlers import Sink
from smtplib import SMTP
async def amain(loop):
cont = Controller(Sink(), hostname='127.0.0.1', port=8025)
cont.start()
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
loop = asyncio.get_event_loop()
loop.create_task(amain(loop=loop))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
import smtplib
s = smtplib.SMTP('127.0.0.1', 8025)
try:
s.set_debuglevel(True)
s.sendmail('[email protected]', ['[email protected]'], """\
Date:17/05/2017,2:18
From: [email protected]
To: [email protected]
Subject: A test
testing
""")
s.quit()
except smtplib.SMTPException:
print("Error: unable to send email")
import traceback
traceback.print_exc()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question