How to use the sendgrid.SendGridClient function in sendgrid

To help you get started, we’ve selected a few sendgrid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sendgrid / sendgrid-python / test / test_mail_v2.py View on Github external
def setUp(self):
        self.sg = SendGridClient(SG_USER, SG_PWD)
        self.maxDiff = None
github sendgrid / sendgrid-python / test / __init__.py View on Github external
def setUp(self):
        self.sg = SendGridClient(SG_USER, SG_PWD)
github bitslabsyr / stack / scripts / notifications / notifier.py View on Github external
def send_email(report, title):
    API_KEY = os.environ.get('SENDGRID_KEY')
    if API_KEY is None:
        print 'No SendGrid API key found! Please set the SENDGRID_KEY env var'
        sys.exit(1)

    sg = SendGridClient(API_KEY, raise_errors=True)

    # Backwards compatability for emails stored as strings, not lists
    emails = report['project_details']['email']
    if type(emails) is not list:
        emails = [emails]

    for address in emails:
        message = Mail()
        message.add_to(address)
        message.set_subject(title)
        message.set_html(generate_email_text(report))
        message.set_from('STACKS ')

        try:
            sg.send(message)
        except SendGridError as e:
github breakthenet / HackMe-Social-Engineering-Challenges / api / views.py View on Github external
pass

        try:
            reply_to_address = reply_to_address.split('<')[1].split('>')[0]
        except:
            pass

        print "to_address", to_address
        print "from_address", from_address
        print "reply_to_address", reply_to_address
        
        if to_address == "bobdole@"+os.environ.get('MAILGUN_DOMAIN', ''):
            if from_address == "tedjones@"+os.environ.get('MAILGUN_DOMAIN', ''):
                plaintext = 'Hey! You may not have lost the password, as I just recently updated it so that could be why you are having trouble logging in. The new password is "eggroll". \n-Bob Dole\nCEO, Veritas Inc.'
                
                sg = sendgrid.SendGridClient(os.environ.get('SENDGRID_USERNAME', ''), os.environ.get('SENDGRID_PASSWORD', ''))
                
                message = sendgrid.Mail()
                message.add_to(reply_to_address)
                message.set_subject("Re: "+request.POST['subject'])
                message.set_html(plaintext)
                message.set_text(plaintext)
                message.set_from("Bob Dole ")
                status, msg = sg.send(message)
                print status
                print msg
                
        elif to_address == "scotty@"+os.environ.get('MAILGUN_DOMAIN', ''):
            print "Email to scotty!"
            if from_address == "kylo@"+os.environ.get('MAILGUN_DOMAIN', ''):
                email_html = request.POST['body-html']
                if type(email_html) is list:
github puppetlabs / py-awsaudit / aws_report.py View on Github external
else:
          user = 'Unable to locate'

        grouped[g].add("ID: " + h['_source']['id'] + " USER: " + user + " TAGS: " + ",".join(h['_source']['tags']))

  # Add a section to our email body for each IAM alias
  for g in grouped:
    doc += (g + " IAM root account: TERMINATED" + "\n")
    for i in grouped[g]:
      doc += ("  " + i + "\n")
    doc += "\n"

  if grouped != {}:
    # Send the email via SendGrid
    if email == True:
      sg = sendgrid.SendGridClient(sg_user, sg_password)

      message = sendgrid.Mail()
      message.add_to(email_to)
      message.set_subject("EC2 Termination Report: " + yesterday_email)
      message.set_text(doc)
      message.set_from(email_from)
      status, msg = sg.send(message)
    else:
      print(doc)
github CenterForOpenScience / osf.io / framework / email / tasks.py View on Github external
def _send_with_sendgrid(from_addr, to_addr, subject, message, mimetype='html', categories=None, attachment_name=None, attachment_content=None, client=None):
    if (settings.SENDGRID_WHITELIST_MODE and to_addr in settings.SENDGRID_EMAIL_WHITELIST) or settings.SENDGRID_WHITELIST_MODE is False:
        client = client or sendgrid.SendGridClient(settings.SENDGRID_API_KEY)
        mail = sendgrid.Mail()
        mail.set_from(from_addr)
        mail.add_to(to_addr)
        mail.set_subject(subject)
        if mimetype == 'html':
            mail.set_html(message)
        else:
            mail.set_text(message)
        if categories:
            mail.set_categories(categories)
        if attachment_name and attachment_content:
            mail.add_attachment_stream(attachment_name, attachment_content)

        status, msg = client.send(mail)
        return status < 400
    else:
github shashankredemption / slack-cleaning-bot / slack_cleaning_bot.py View on Github external
# -*- coding: utf-8 -*-
import os
from slacker import Slacker
import sendgrid
from datetime import datetime
from pytz import timezone

sg = sendgrid.SendGridClient(os.environ['SENDGRID_USERNAME'], os.environ['SENDGRID_PASSWORD'], raise_errors=True)


def slack_cleaning_bot():
    slack = Slacker(os.environ['SLACK_KEY'])
    people = ['canzhi', 'stevensuckscock', 'neeloy', 'rohan', 'amillman', 'steven']
    day_of_year = datetime.now(tz=timezone('US/Pacific')).timetuple().tm_yday
    message = "today is @" + str(people[day_of_year%6]) + "'s day to do the dishes. Tomorow is @" + str(people[(day_of_year+1)%6])
    slack.chat.post_message('#cleaning', message)
    im_david = '👀 good shit go౦ԁ sHit👌 thats ✔ some good👌shit right👌there👌👌 rightthere ✔if i do ƽaү so my self'.decode('utf-8')
    david_message = sendgrid.Mail(to='david@dtbui.com', subject=im_david, html='<strong>' + message + '</strong>', text=message, from_email="shashank@thenothing.co")
    message = sendgrid.Mail(to='rohanpai@berkeley.edu', subject='CLEAN THE DISHWASHER TODAY', html='<strong> IT IS YOUR LUCKY DAY MOTHAFUCKA</strong>', text='IT IS YOUR LUCKY DAY MOTHAFUCKA', from_email="shashank@thenothing.co")
    try:
        d_status, d_msg = sg.send(david_message)
        if people[day_of_year%6] == 'rohan':
            status, msg = sg.send(message)
    except SendGridClientError:
github xeroc / piston-cli / examples / notification-mail.py View on Github external
from piston.steem import Steem
import os
import json
import sendgrid
steem = Steem()
sg = sendgrid.SendGridClient(
    os.environ['SENDGRID_USERNAME'],
    os.environ['SENDGRID_PASSWORD']
)
message = sendgrid.Mail()
addresses = {"xeroc": "mail@xeroc.org"}
# addresses = os.environ["ADDRESSES"]
for c in steem.stream_comments():
    for user in addresses.keys():
        if "@%s" % user in c["body"]:
            message.add_to(addresses[user])
            message.set_subject('Notification on Steem')
            message.set_text(
                "You have been messaged by %s " % (c["author"]) +
                "in the post @%s/%s" % (c["author"], c["permlink"]) +
                "\n\n" +
                "You can read the post on Steemit.com:\n" +
github crowdresearch / daemo / crowdsourcing / backends / sendgrid_backend.py View on Github external
def __init__(self, fail_silently=False, **kwargs):
        super(SendGridBackend, self).__init__(fail_silently=fail_silently)
        self.api_key = getattr(settings, "SENDGRID_API_KEY", None)

        if self.api_key is None:
            raise ImproperlyConfigured('''SENDGRID_API_KEY not declared in settings.py''')

        self.client = sendgrid.SendGridClient(
            self.api_key,
            raise_errors=not fail_silently)