Exemplo n.º 1
0
 def connect(self):
     try:
         super(SMTP, self).connect()
     except smtplib.SMTPServerDisconnected as error:
         logger.exception(error.message)
         raise InternalServerError(
             'Unexpectedly Connection closed with given server')
Exemplo n.º 2
0
 def authenticate(self, connection_quit=True):
     """
     This first connects with POP server. It then tries to login to server.
     """
     try:
         self.connection.user(self.email)
         self.connection.pass_(self.password)
     except poplib.error_proto as error:
         logger.exception(error.message)
         raise InvalidUsage(
             'Invalid credentials provided. Could not authenticate with POP server',
             additional_error_info=dict(pop_error=error.message))
Exemplo n.º 3
0
 def authenticate(self, connection_quit=True):
     """
     This first connects with IMAP server. It then tries to login to server.
     :type connection_quit: bool
     """
     try:
         self.connection.login(self.email, self.password)
     except imaplib.IMAP4_SSL.error as error:
         logger.exception(error.message)
         raise InvalidUsage(
             'Could not authenticate with IMAP server.',
             additional_error_info=dict(imap_error=error.message))
Exemplo n.º 4
0
def delete_emails(mail_connection, msg_ids, subject):
    """
    This deletes email(s) with given message ids and subject
    """
    try:
        msg_ids = msg_ids.replace(' ', ',')
        # Change the Deleted flag to delete the email from Inbox
        mail_connection.store(msg_ids, '+FLAGS', r'(\Deleted)')
        status, response = mail_connection.expunge()
        assert status == 'OK'
        print "Email(s) deleted with subject: %s" % subject
        mail_connection.close()
        mail_connection.logout()
    except imaplib.IMAP4_SSL.error as error:
        logger.exception(error.message)
Exemplo n.º 5
0
 def connect(self):
     """
     This connects with SMTP/IMAP/POP server and sets the value of attribute 'connection'.
     """
     try:
         self.connection = self.client(
             self.host, port=self.port) if self.port else self.client(
                 self.host)
     except gaierror as error:
         logger.exception(error.message)
         raise InternalServerError(
             'Error occurred while connecting with given server')
     except SSLError as error:
         logger.exception(error.strerror)
         raise InternalServerError(
             'Error occurred while connecting with given server',
             additional_error_info=dict(email_client_error=error.strerror))
Exemplo n.º 6
0
 def authenticate(self, connection_quit=True):
     """
     This first connects with SMTP server. It then tries to login to server.
     """
     try:
         self.connection.login(self.email, self.password)
     except smtplib.SMTPAuthenticationError as error:
         logger.exception(error.smtp_error)
         raise InvalidUsage(
             'Invalid credentials provided. Could not authenticate with SMTP server',
             additional_error_info=dict(smtp_error=error.smtp_error))
     except smtplib.SMTPException as error:
         logger.exception(error.message)
         raise InternalServerError(
             'Could not authenticate with SMTP server',
             additional_error_info=dict(smtp_error=error.message))
     if connection_quit:
         self.connection.quit()
Exemplo n.º 7
0
"""
    Run Celery Worker

For Celery to run from command line, script runs as separate process with celery command

 Usage: open terminal cd to talent-flask-services directory

 Run the following command to start celery worker:

    $ celery -A email_campaign_service.email_campaign_app.celery_app worker --concurrency=4 --loglevel=info
"""

# Service Specific
from email_campaign_service.common.talent_celery import CELERY_WORKER_ARGS
from email_campaign_service.email_campaign_app import celery_app, logger, app
from email_campaign_service.common.talent_config_manager import TalentConfigKeys
from email_campaign_service.common.campaign_services.campaign_utils import CampaignUtils

try:
    logger.info("Starting Celery worker for:%s" % app.name)
    celery_app.start(argv=CELERY_WORKER_ARGS + [CampaignUtils.EMAIL] +
                     ['-n', CampaignUtils.EMAIL])
except Exception as e:
    logger.exception(
        "Couldn't start Celery worker for email_campaign_service in "
        "%s environment." % (app.config[TalentConfigKeys.ENV_KEY]))