def send_mail(self, sender, to, subject, text, html=None, reply_to=None):
        """
        Send email to user.
        """
        encoding = 'utf-8'
        text_args = (text, encoding)
        html_args = (html, encoding) if html else None
        headers = []

        if reply_to:
            headers.append(('Reply-To', reply_to))

        payload, mail_from, rcpt_to, msg_id = pyzmail.compose_mail(
            sender, [to],
            subject,
            encoding,
            text_args,
            html=html_args,
            headers=headers)

        try:
            pyzmail.send_mail2(payload, mail_from, rcpt_to, **self.smtp_params)
        except Exception as e:
            logger.exception('Unable to send email to the receipient.')
            raise Exception('Unable to send email to the receipient.')
Beispiel #2
0
def actually_mail(mails):
    print 'Actually sending emails...'

    smtp_host = 'smtp.helsinki.fi'
    smtp_port = 587
    smtp_mode = 'tls'
    smtp_login = raw_input('SMTP Username: '******'SMTP Password: '******'Failed recipients'
            for recipient, (code, msg) in ret.iteritems():
                print 'code=%d recipient=%s error=%s' % (code, recipient, msg)
            break
        else:
            print 'Sent mail to recipients %s' % rcpt_to
Beispiel #3
0
def actually_mail(mails):
    print "Actually sending emails..."

    smtp_host = "smtp.helsinki.fi"
    smtp_port = 587
    smtp_mode = "tls"
    smtp_login = raw_input("SMTP Username: "******"SMTP Password: "******"Failed recipients"
            for recipient, (code, msg) in ret.iteritems():
                print "code=%d recipient=%s error=%s" % (code, recipient, msg)
            break
        else:
            print "Sent mail to recipients %s" % rcpt_to
Beispiel #4
0
    def send_mail(self, sender, to, subject, text, html=None, reply_to=None):
        """
        Send email to user.

        Arguments:
        sender - (string or tuple) email or a tuple of the form
            ('Name', '*****@*****.**')
        to - (string) - recipient address
        subject - (str) The subject of the message
        text - (tuple or None) The text version of the message
        html - (tuple or None) The HTML version of the message
        reply_to - (string or tuple) email or a tuple of the form
            ('Name', '*****@*****.**')
        """
        encoding = 'utf-8'
        text_args = (text, encoding)
        html_args = (html, encoding) if html else None
        headers = []

        reply_to_tuple = self._convert_email_tuple(reply_to)
        sender_tuple = self._convert_email_tuple(sender)

        if reply_to_tuple and reply_to_tuple[1]:
            # only append header when there is reply to email
            reply_to_value = pyzmail.generate.format_addresses(
                [
                    reply_to_tuple,
                ], header_name='Reply-To', charset=encoding)
            headers.append(('Reply-To', reply_to_value))

        payload, mail_from, rcpt_to, msg_id = pyzmail.compose_mail(
            sender_tuple, [to],
            subject,
            encoding,
            text_args,
            html=html_args,
            headers=headers)

        try:
            pyzmail.send_mail2(payload, mail_from, rcpt_to, **self.smtp_params)
        except Exception:
            logger.exception('Unable to send email to the receipient.')
            raise Exception('Unable to send email to the receipient.')