Ejemplo n.º 1
0
def send_hello_email(smtp: SMTP):
    envelope = envelopes.Envelope(
        from_addr=(u"*****@*****.**", u"From me"),
        to_addr=(u"*****@*****.**", u"To World"),
        subject=u"Hello",
        text_body=u"World!",
    )
    smtp.send_envelope(envelope)
Ejemplo n.º 2
0
def _send_email(msg_info):
    """Create and send commit notification email."""
    sender = _get_sender(msg_info['pusher_email'])
    recipient = os.environ.get('GITHUB_COMMIT_EMAILER_RECIPIENT')

    if sender is None or recipient is None:
        logging.error('sender and recipient config vars must be set.')
        raise ValueError('sender and recipient config vars must be set.')

    recipient_cc = os.environ.get('GITHUB_COMMIT_EMAILER_RECIPIENT_CC', None)
    reply_to = os.environ.get('GITHUB_COMMIT_EMAILER_REPLY_TO', None)
    approved = os.environ.get('GITHUB_COMMIT_EMAILER_APPROVED_HEADER', None)
    subject = _get_subject(msg_info['repo'], msg_info['message'])

    body = """Branch: {branch}
Revision: {revision}
Author: {pusher}

Log Message:
------------
{message}

Modified Files:
---------------
{changed_files}

Compare: {compare_url}
""".format(**msg_info)

    msg = envelopes.Envelope(
        to_addr=recipient,
        from_addr=sender,
        subject=subject,
        text_body=body,
        cc_addr=recipient_cc,
    )

    if reply_to is not None:
        msg.add_header('Reply-To', reply_to)
    if approved is not None:
        msg.add_header('Approved', approved)

    # Disable SendGrid click tracking.
    send_grid_disable_click_tracking = json.dumps(
        {'filters': {
            'clicktrack': {
                'settings': {
                    'enable': 0
                }
            }
        }})
    msg.add_header('X-SMTPAPI', send_grid_disable_click_tracking)

    smtp = envelopes.connstack.get_current_connection()
    logging.info('Sending email: {0}'.format(msg))
    smtp.send(msg)
Ejemplo n.º 3
0
 def send(self, subject, body, sender_name, to_addr_or_tuple, headers=None):
     headers = headers or {}
     envelope = envelopes.Envelope(
         from_addr=(self.email, sender_name),
         to_addr=to_addr_or_tuple,
         subject=subject,
         text_body=body,
         headers=headers,
     )
     self.gmail.send(envelope)
Ejemplo n.º 4
0
    def send(self, to, subject, content):
        envelope = envelopes.Envelope(
            from_addr=self._from,
            to_addr=to,
            subject=subject,
            text_body=content
        )

        if not self.kernel.getConfig('debug'):
            envelope.send('localhost', port=25)
        else:
            print envelope
Ejemplo n.º 5
0
    def send_submission_notification_email(self):
        """Sends an email notification

        This is used in the GDC to notify the user services team
        about submitting a project
        """

        from_addr = self.app_config.get('EMAIL_FROM_ADDRESS')
        to_addr = self.app_config.get('EMAIL_SUPPORT_ADDRESS')
        preformatted = self.app_config.get('EMAIL_NOTIFICATION_SUBMISSION')
        subject = (
            "[SUBMISSION] Project {project_id} has been submitted by {user}".
            format(project_id=self.project_id, user=self.user.username))

        number_of_cases = 0
        number_of_submitted_files = 0
        experimental_strategies = set()
        for entity in self.entities:
            if entity.node.label == 'case':
                number_of_cases += 1

            if utils.is_node_file(entity.node):
                ex_strategy = entity.node.props.get('experimental_strategy')
                if ex_strategy:
                    experimental_strategies.add(ex_strategy)

        # Construct body
        text_body = preformatted.format(
            project_id=self.project_id,
            user_id=self.user.username,
            number_of_cases=number_of_cases,
            number_of_submitted_files=number_of_submitted_files,
            experimental_strategies=','.join(experimental_strategies),
        )

        # Construct email
        envelope = envelopes.Envelope(
            from_addr=from_addr,
            to_addr=to_addr,
            subject=subject,
            text_body=text_body,
        )

        description = "email '{}' to {}".format(subject, to_addr)
        self.logger.info("Sending " + description)

        # Send email (synchronous)
        connection = envelopes.SMTP(**self.smtp_conf)
        connection.send(envelope)

        self.logger.info("Sent " + description)
Ejemplo n.º 6
0
 def test_constructor(self):
     envelop = env.Envelope(5, 5)
     self.assertEqual((envelop.width, envelop.height), (5, 5))
Ejemplo n.º 7
0
 def test_greater_envelop(self):
     first_envelop = env.Envelope(14, 18)
     second_envelop = env.Envelope(10, 12)
     self.assertGreater(first_envelop, second_envelop)
Ejemplo n.º 8
0
 def test_less_envelop(self):
     first_envelop = env.Envelope(4, 8)
     second_envelop = env.Envelope(10, 12)
     self.assertLess(first_envelop, second_envelop)
Ejemplo n.º 9
0
def send_hello_email(smtp: SMTP):
    envelope = envelopes.Envelope(from_addr=(u'*****@*****.**', u'From me'),
                                  to_addr=(u'*****@*****.**', u'To World'),
                                  subject=u'Hello',
                                  text_body=u"World!")
    smtp.send_envelope(envelope)