Commit 76327957 authored by juga's avatar juga
Browse files

Add argument to set the SMTP server to use

parent 660b371a
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -71,6 +71,12 @@ def create_parser():
        help="Email file path to forward to remailers."
        "It can also be pass via STDIN.",
    )
    parser.add_argument(
        "-t",
        "--smtp",
        help="SMTP server to use to send an Email, in the form domain[:port].",
        default="localhost",
    )
    return parser


+12 −0
Original line number Diff line number Diff line
@@ -6,6 +6,9 @@ import os
import re
import smtplib

import configargparse
import urllib3

from mixnet import defaults, exceptions

logger = logging.getLogger(__name__)
@@ -93,6 +96,15 @@ def create_outgoing_msg(me, to, subject, body):

def send_email(mail_str):
    mail = email.message_from_string(mail_str)
    # Get the parser singleton
    parser = configargparse.get_argument_parser()
    args = parser.parse_args()
    d, p = parse_domain_port(args.smtp)
    s = smtplib.SMTP("localhost")
    s.send_message(mail)
    s.quit()


def parse_domain_port(domain_port):
    u = urllib3.util.url.parse_url(domain_port)
    return (u.host, u.port or 25)
+6 −0
Original line number Diff line number Diff line
@@ -63,6 +63,12 @@ def create_parser():
        help="Email file path to forward to remailers. "
        "It can also be pass via STDIN.",
    )
    parser.add_argument(
        "-t",
        "--smtp",
        help="SMTP server to use to send an Email, in the form domain[:port].",
        default="localhost",
    )
    return parser


+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ install_requires =
    colorlog >= 4.0
    configargparse >= 0.13
    pEp >= 2.0
    urllib3 >= 1.24
# To automatically write the version from a SCM.
setup_requires = setuptools_scm