Example #1
0
 def send(self):
     """
     Send the message through the SMTP.
     """
     msg = self._compose_message()
     config_obj = config.Config()
     setup = config_obj.get_account_setup()
     server_out = "smtp.{}:{}".format(
             setup["server_address"], setup["port_out"])
     try:
         server = smtplib.SMTP(server_out)
         server.ehlo_or_helo_if_needed()
         if server.has_extn("STARTTLS"):
             server.starttls(
                 keyfile=setup.get("keyfile"), certfile=setup.get("certfile"))
         else:
             _LOG.warning("Server does not support STARTTLS.")
         server.ehlo_or_helo_if_needed()
         server.login(setup["user_address"],
                      config_obj.decrypt_password(setup["password"]))
         server.sendmail(setup["user_address"],
                         self.recipients, msg.as_string())
         server.quit()
         _LOG.debug("Email was sent successfully.")
         return True
     except socket.error as exc:
         raise exceptions.NoInternetError(exc) from exc
     except (smtplib.SMTPException, SSLError) as exc:
         raise EmailSendingError(exc) from exc
Example #2
0
 def reply_all():
     '''
     Send a reply to the sender and all the recipients
     of the original message.
     '''
     # pick email addresses of the main sender and of all
     # the recipients except myself:
     setup = config.Config().get_account_setup()
     app.box['new_message'].recipients = \
         [message['From'][0][1]] + \
         [msg[1] for msg in message['To'] if
             msg[1] != '@'.join([setup['user_address'],
                                 setup['server_address']])]
     window.load_view(VIEWS_MAP["new_message_initial_view"],
                      {'original_msg': message, 'action': 'reply_all'})
Example #3
0
def test_smtp_connection(custom_config=None):
    """
    Test SMTP connection.
    """
    setup = custom_config or config.Config().get_account_setup()
    server_out = "{}:{}".format(setup["SMTP_server"], setup["SMTP_port"])
    try:
        server = smtplib.SMTP(server_out)
        server.ehlo_or_helo_if_needed()
        if server.has_extn("STARTTLS"):
            server.starttls(keyfile=setup.get("keyfile"),
                            certfile=setup.get("certfile"))
        server.ehlo_or_helo_if_needed()
        server.login(setup["address"], setup["password"])
        server.quit()
    except socket.error as exc:
        raise exceptions.NoInternetError(exc) from exc
    except (smtplib.SMTPException, SSLError) as exc:
        raise EmailSendingError(exc) from exc
Example #4
0
 def __init__(self, custom_config=None):
     self._lock = threading.RLock()
     self._conn = None
     self._positive_response_code = "OK"
     self._setup = custom_config or config.Config().get_account_setup()
     self._sent_box_name = self._setup["sent_folder"]
Example #5
0
 def __init__(self):
     self._conn = None
     self._positive_response_code = "OK"
     self._config_obj = config.Config()
     self._setup = self._config_obj.get_account_setup()
     self._sent_box_name = self._setup["sent_box_name"]