コード例 #1
0
 def test_send_with_attachments(self, mock_request):
     mock_request.return_value = self.mock_response(self.json_response)
     message = pystmark.Message(sender='*****@*****.**', text='hi',
                                to='*****@*****.**')
     message.attach_binary(urandom(64), 'test.pdf')
     r = pystmark.send(message, api_key=POSTMARK_API_TEST_KEY)
     self.assertValidJSONResponse(r, self.response)
コード例 #2
0
def send_email(to, subject, body_text=None, body_html=None):
    # Send a single message
    message = pystmark.Message(sender=config.EMAIL_SENDER,
                               to=to,
                               subject=subject,
                               text=body_text,
                               html=body_html)
    pystmark.send(message, api_key=config.POSTMARKAPP_API_KEY)
コード例 #3
0
 def test_send_with_unicode(self, mock_request):
     test_text = u'Hi Jos\xe9'
     mock_request.return_value = self.mock_response(self.json_response)
     message = pystmark.Message(sender='*****@*****.**', text=test_text,
                                to='*****@*****.**')
     pystmark.send(message, api_key=POSTMARK_API_TEST_KEY)
     request_data = mock_request.mock_calls[0][2]['data']
     str(request_data)  # ssl lib will convert to str
     self.assertEqual(json.loads(request_data)['TextBody'], test_text)
コード例 #4
0
 def test_send_with_attachments_content_id(self, mock_request):
     content_id = 'cid:%[email protected]' % (uuid.uuid4())
     mock_request.return_value = self.mock_response(self.json_response)
     message = pystmark.Message(sender='*****@*****.**', text='hi',
                                to='*****@*****.**')
     message.attach_binary(urandom(64), 'test.pdf',
                           content_type='image/png',
                           content_id=content_id)
     r = pystmark.send(message, api_key=POSTMARK_API_TEST_KEY)
     self.assertValidJSONResponse(r, self.response)
コード例 #5
0
 def test_advanced_api(self, mock_request):
     mock_request.return_value = self.mock_response(self.json_response)
     message = pystmark.Message(sender='*****@*****.**', text='hey')
     sender = pystmark.Sender(message=message,
                              api_key=POSTMARK_API_TEST_KEY)
     r = sender.send(dict(to='*****@*****.**'), test=True)
     self.assertValidJSONResponse(r, self.response)
     url = sender._get_api_url(secure=True)
     message.to = '*****@*****.**'
     headers = sender._get_headers(api_key=POSTMARK_API_TEST_KEY)
     mock_request.assert_called_with('POST', url, data=message.json(),
                                     headers=headers)
コード例 #6
0
def send_mail(to, subject, text, sender=constants.MAILER_FROM):
    if constants.ENVIRONMENT == 'test':
        logging.warn(
            'Skipping sending mail to {} due to ENVIRONMENT == test'.format(
                to))
        return
    message = pystmark.Message(sender=sender,
                               to=to,
                               subject=subject,
                               text=text)
    pystmark.send(message, api_key=constants.MAILER_POSTMARK_API_KEY)
    logging.info('Send mail to {} with subject `{}`'.format(to, subject))
コード例 #7
0
 def send_email(self):
     outdateds = self.get_outdated_requirements()
     if outdateds:
         html = render_template('email.html', reqs=outdateds)
         message = pystmark.Message(
             sender='*****@*****.**',
             to=self.email,
             subject="There are updated packages in PyPI",
             html=html)
         response = pystmark.send(message,
                                  current_app.config['POSTMARK_APIKEY'])
         response.raise_for_status()
     else:
         logger.info("No outdated requirement.")
コード例 #8
0
ファイル: mail.py プロジェクト: thelebster/selfmailbot
def send_mail(to, subject, text, attachment=None, attachment_name=''):
    message = pystmark.Message(
        sender=env('MAIL_FROM'),
        to=to,
        subject=subject,
        text=text,
    )

    if attachment is not None:
        message.attach_binary(attachment.read(), attachment_name)

    result = pystmark.send(message, api_key=env('POSTMARK_API_KEY'))
    result.raise_for_status()

    return result
コード例 #9
0
def _send_email(tupl):
    subject, message = tupl
    c = yaml.safe_load(open('../postmark.yml'))
    """
    a decorator to send an email

    """
    msg = pystmark.Message(sender=c['from'],
                           to=c['to'],
                           subject=subject,
                           html=message,
                           tag="tests")
    response = pystmark.send(msg, api_key=c['api_key'])
    try:
        response.raise_for_status()
    except Exception as e:
        print e.message
コード例 #10
0
ファイル: email.py プロジェクト: barrukurniawan/pytavia
    def send(self, params):
        message_key = params["message_key"]
        email_data = params["email_data"]
        to_email = params["email_to"]
        subject_email = params["email_subject"]
        message_tag = params["message_tag"]

        email_text = email_message.message[message_key]
        email_return = templating.Templating.render(email_text, email_data)

        message = pystmark.Message(sender=config.G_POSTMARK_API_SENDER_EMAIL,
                                   to=to_email,
                                   subject=subject_email,
                                   tag=message_tag,
                                   html=email_return)

        message.track_opens = True
        response = pystmark.send(message,
                                 api_key=config.G_POSTMARK_API_SERVER_TOKEN)
        # we have to check for failed to send emails and log them
        json_response = response._data
        print json_response
コード例 #11
0
def suggestCallScriptApi():
    try:
        newCallScript = request.get_json()
        if not request.userId or 'g-recaptcha-response' in newCallScript:
            if 'g-recaptcha-response' not in newCallScript:
                raise Exception("No recaptcha response! Are you a robot!?")
            captchaResult = requests.post(
                "https://www.google.com/recaptcha/api/siteverify",
                params={
                    'secret': app.config['GOOGLE_RECAPTCHA_SECRET'],
                    'response': newCallScript['g-recaptcha-response'],
                    'remoteip': request.remote_addr
                },
                headers={
                    'Referer': app.config['BASE_URL'],
                })

            if captchaResult.status_code != 200:
                raise Exception("Exception running captcha verification")
            captchaResultObj = captchaResult.json()
            if captchaResultObj['success'] == False:
                errorCodes = captchaResultObj.get("error-codes",
                                                  "Unknown error")
                raise Exception(
                    "Exception running captcha verification: {}".format(
                        errorCodes))
            del newCallScript['g-recaptcha-response']

        jsonschema.validate(newCallScript, callScriptSchema)
        newCallScript['approved'] = False
        newCallScript['approvalCode'] = str(ObjectId())
        res = putCallScript(request.get_json(), True)

        campaignDoc = mongo.db.campaigns.find_one(
            {'_id': ObjectId(newCallScript['campaign'])})
        adminsCursor = mongo.db.users.find(
            {'_id': {
                '$in': campaignDoc['owners']
            }})
        approvalLink = "{0}/api/approveCallScript?approval={1}".format(
            app.config['BASE_URL'], newCallScript['approvalCode'])

        emailText = """<p>A new call script has been submitted to your campaign!</p>
<p>You can approve this call script by going here <a href="{0}">{0}</a></p>.
<p><strong>Title:</strong> {}</p>
<p><strong>Blurb:</strong> {}</p>
<p><strong>Applies To:</strong> {}</p>
<p><strong>Text:</strong> {}</p>
<p><strong>Tags:</strong> {}</p>
<p><strong>Submitted By:</strong> {}</p>
""".format(approvalLink, newCallScript['title'], newCallScript['blurb'],
           ', '.join(newCallScript['appliesTo']), newCallScript['text'],
           ', '.join(newCallScript.get('tags', [])),
           newCallScript.get('submittedBy', ''))

        for admin in adminsCursor:
            message = pystmark.Message(sender='*****@*****.**',
                                       to=admin['email'],
                                       subject='New Suggested Call Script',
                                       html=emailText)
            pystmark.send(message, api_key=app.config['POSTMARK_API_KEY'])
        return json.dumps({'status': 'OK', 'result': 'Submitted!'})

    except Exception as e:
        return json.dumps({'status': 'FAIL', 'error_message': str(e)})