Python google.appengine.api.mail.send_mail() Examples

The following are 21 code examples of google.appengine.api.mail.send_mail(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module google.appengine.api.mail , or try the search function .
Example #1
Source File: task.py    From github-stats with MIT License 6 votes vote down vote up
def send_mail_notification(subject, body, to=None, **kwargs):
  if not config.CONFIG_DB.feedback_email:
    return
  brand_name = config.CONFIG_DB.brand_name
  sender = '%s <%s>' % (brand_name, config.CONFIG_DB.feedback_email)
  subject = '[%s] %s' % (brand_name, subject)
  if config.DEVELOPMENT:
    logging.info(
      '\n'
      '######### Deferring sending this email: #############################'
      '\nFrom: %s\nTo: %s\nSubject: %s\n\n%s\n'
      '#####################################################################',
      sender, to or sender, subject, body
    )
  deferred.defer(mail.send_mail, sender, to or sender, subject, body, **kwargs)


###############################################################################
# Admin Notifications
############################################################################### 
Example #2
Source File: report_generator.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def SendReport(self, report):
    """Emails an exception report.

    Args:
      report: A string containing the report to send.
    """
    subject = ('Daily exception report for app "%s", major version "%s"'
               % (self.app_id, self.major_version))
    report_text = saxutils.unescape(re.sub('<[^>]+>', '', report))
    mail_args = {
        'sender': self.sender,
        'subject': subject,
        'body': report_text,
        'html': report,
    }
    if self.to:
      mail_args['to'] = self.to
      self.send_mail(**mail_args)
    else:
      self.send_mail_to_admins(**mail_args) 
Example #3
Source File: ui.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def _email_html(to, subject, body):
  """Sends an email including a textual representation of the HTML body.

  The body must not contain <html> or <body> tags.
  """
  mail_args = {
    'body': saxutils.unescape(re.sub(r'<[^>]+>', r'', body)),
    'html': '<html><body>%s</body></html>' % body,
    'sender': 'no_reply@%s.appspotmail.com' % app_identity.get_application_id(),
    'subject': subject,
  }
  try:
    if to:
      mail_args['to'] = to
      mail.send_mail(**mail_args)
    else:
      mail.send_mail_to_admins(**mail_args)
    return True
  except mail_errors.BadRequestError:
    return False 
Example #4
Source File: ui.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def _email_html(to, subject, body):
  """Sends an email including a textual representation of the HTML body.

  The body must not contain <html> or <body> tags.
  """
  mail_args = {
    'body': saxutils.unescape(re.sub(r'<[^>]+>', r'', body)),
    'html': '<html><body>%s</body></html>' % body,
    'sender': 'no_reply@%s.appspotmail.com' % app_identity.get_application_id(),
    'subject': subject,
  }
  try:
    if to:
      mail_args['to'] = to
      mail.send_mail(**mail_args)
    else:
      mail.send_mail_to_admins(**mail_args)
    return True
  except mail_errors.BadRequestError:
    return False 
Example #5
Source File: ui.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def _email_html(to, subject, body):
  """Sends an email including a textual representation of the HTML body.

  The body must not contain <html> or <body> tags.
  """
  mail_args = {
    'body': saxutils.unescape(re.sub(r'<[^>]+>', r'', body)),
    'html': '<html><body>%s</body></html>' % body,
    'sender': 'no_reply@%s.appspotmail.com' % app_identity.get_application_id(),
    'subject': subject,
  }
  try:
    if to:
      mail_args['to'] = to
      mail.send_mail(**mail_args)
    else:
      mail.send_mail_to_admins(**mail_args)
    return True
  except mail_errors.BadRequestError:
    return False 
Example #6
Source File: ui.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def _email_html(to, subject, body):
  """Sends an email including a textual representation of the HTML body.

  The body must not contain <html> or <body> tags.
  """
  mail_args = {
    'body': saxutils.unescape(re.sub(r'<[^>]+>', r'', body)),
    'html': '<html><body>%s</body></html>' % body,
    'sender': 'no_reply@%s.appspotmail.com' % app_identity.get_application_id(),
    'subject': subject,
  }
  try:
    if to:
      mail_args['to'] = to
      mail.send_mail(**mail_args)
    else:
      mail.send_mail_to_admins(**mail_args)
    return True
  except mail_errors.BadRequestError:
    return False 
Example #7
Source File: ui.py    From luci-py with Apache License 2.0 6 votes vote down vote up
def _email_html(to, subject, body):
  """Sends an email including a textual representation of the HTML body.

  The body must not contain <html> or <body> tags.
  """
  mail_args = {
    'body': saxutils.unescape(re.sub(r'<[^>]+>', r'', body)),
    'html': '<html><body>%s</body></html>' % body,
    'sender': 'no_reply@%s.appspotmail.com' % app_identity.get_application_id(),
    'subject': subject,
  }
  try:
    if to:
      mail_args['to'] = to
      mail.send_mail(**mail_args)
    else:
      mail.send_mail_to_admins(**mail_args)
    return True
  except mail_errors.BadRequestError:
    return False 
Example #8
Source File: user_signup.py    From python-docs-samples with Apache License 2.0 6 votes vote down vote up
def post(self):
        user_address = self.request.get('email_address')

        if not mail.is_email_valid(user_address):
            self.get()  # Show the form again.
        else:
            confirmation_url = create_new_user_confirmation(user_address)
            sender_address = (
                'Example.com Support <example@{}.appspotmail.com>'.format(
                    app_identity.get_application_id()))
            subject = 'Confirm your registration'
            body = """Thank you for creating an account!
Please confirm your email address by clicking on the link below:

{}
""".format(confirmation_url)
            mail.send_mail(sender_address, user_address, subject, body)
# [END send-confirm-email]
            self.response.content_type = 'text/plain'
            self.response.write('An email has been sent to {}.'.format(
                user_address)) 
Example #9
Source File: send_mail.py    From python-docs-samples with Apache License 2.0 6 votes vote down vote up
def send_approved_mail(sender_address):
    # [START send_mail]
    mail.send_mail(sender=sender_address,
                   to="Albert Johnson <Albert.Johnson@example.com>",
                   subject="Your account has been approved",
                   body="""Dear Albert:

Your example.com account has been approved.  You can now visit
http://www.example.com/ and sign in using your Google Account to
access new features.

Please let us know if you have any questions.

The example.com Team
""")
    # [END send_mail] 
Example #10
Source File: email.py    From alertlib with MIT License 6 votes vote down vote up
def _send_to_gae_email(self, message, email_addresses, cc=None, bcc=None,
                           sender=None):
        gae_mail_args = {
            'subject': self._get_summary(),
            'sender': _get_sender(sender),
            'to': email_addresses,      # "x@y" or "Full Name <x@y>"
        }
        if cc:
            gae_mail_args['cc'] = cc
        if bcc:
            gae_mail_args['bcc'] = bcc
        if self.html:
            # TODO(csilvers): convert the html to text for 'body'.
            # (see base.py about using html2text or similar).
            gae_mail_args['body'] = message
            gae_mail_args['html'] = message
        else:
            gae_mail_args['body'] = message
        google_mail.send_mail(**gae_mail_args) 
Example #11
Source File: errorhandling.py    From MyLife with MIT License 6 votes vote down vote up
def log_error(subject, message, *args):
	if args:
		try:
			message = message % args
		except:
			pass

	logging.error(subject + ' : ' + message)

	subject = 'MyLife Error: ' + subject
	app_id = app_identity.get_application_id()
	sender = "MyLife Errors <errors@%s.appspotmail.com>" % app_id
	try:
		to = Settings.get().email_address
		mail.check_email_valid(to, 'To')
		mail.send_mail(sender, to, subject, message)
	except:
		mail.send_mail_to_admins(sender, subject, message) 
Example #12
Source File: attachment.py    From python-docs-samples with Apache License 2.0 5 votes vote down vote up
def post(self):
        f = self.request.POST['file']
        mail.send_mail(sender='example@{}.appspotmail.com'.format(
            app_identity.get_application_id()),
                       to="Albert Johnson <Albert.Johnson@example.com>",
                       subject="The doc you requested",
                       body="""
Attached is the document file you requested.

The example.com Team
""",
                       attachments=[(f.filename, f.file.read())])
# [END send_attachment]
        self.response.content_type = 'text/plain'
        self.response.write('Sent {} to Albert.'.format(f.filename)) 
Example #13
Source File: mail_test.py    From python-docs-samples with Apache License 2.0 5 votes vote down vote up
def testMailSent(self):
        mail.send_mail(to='alice@example.com',
                       subject='This is a test',
                       sender='bob@example.com',
                       body='This is a test e-mail')
        messages = self.mail_stub.get_sent_messages(to='alice@example.com')
        self.assertEqual(1, len(messages))
        self.assertEqual('alice@example.com', messages[0].to)
# [END mail_example] 
Example #14
Source File: header.py    From python-docs-samples with Apache License 2.0 5 votes vote down vote up
def send_example_mail(sender_address, email_thread_id):
    # [START send_mail]
    mail.send_mail(sender=sender_address,
                   to="Albert Johnson <Albert.Johnson@example.com>",
                   subject="An example email",
                   body="""
The email references a given email thread id.

The example.com Team
""",
                   headers={"References": email_thread_id})
    # [END send_mail] 
Example #15
Source File: main.py    From billing-export-python with Apache License 2.0 5 votes vote down vote up
def SendEmail(context, recipients):
    """Send alert/daily summary email."""
    emailbody = EMAIL_TEMPLATE.render(context)

    if not recipients:
        logging.info('no recipients for email, using configured default: ' +
                     config.default_to_email)
        recipients = [config.default_to_email]
    mail.send_mail(sender=app_identity.get_service_account_name(),
                   subject='Billing Summary For ' + context['project'],
                   body=emailbody,
                   html=emailbody,
                   to=recipients)
    logging.info('sending email to ' + ','.join(recipients) + emailbody) 
Example #16
Source File: report_generator.py    From python-compat-runtime with Apache License 2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
    super(ReportGenerator, self).__init__(*args, **kwargs)


    self.send_mail = mail.send_mail
    self.send_mail_to_admins = mail.send_mail_to_admins 
Example #17
Source File: process_emails.py    From loaner with Apache License 2.0 5 votes vote down vote up
def post(self):
    """Processes POST request."""
    kwargs = self.request.params.items()
    email_dict = {}
    for key, value in kwargs:
      email_dict[key] = value

    try:
      mail.send_mail(**email_dict)
    except mail.InvalidEmailError as error:
      logging.error(
          'Email helper failed to send mail due to an error: %s. (Kwargs: %s)',
          error.message, kwargs) 
Example #18
Source File: mailers.py    From crmint with Apache License 2.0 5 votes vote down vote up
def finished_pipeline(self, pipeline):
    recipients = self.recipients(pipeline.recipients)
    if recipients:
      subject = "Pipeline %s %s." % (pipeline.name, pipeline.status)
      mail.send_mail(sender=self.SENDER,
                     to=recipients,
                     subject=subject,
                     body=subject) 
Example #19
Source File: send_mail.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def post(self):
        self.send_mail(sender=self.request.get('sender'),
                       subject=self.request.get('subject'),
                       to=self.request.get('to'),
                       body=self.request.get('body')) 
Example #20
Source File: send_mail.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def send_mail(sender, subject, to, body):
        """Send mail.
        """
        logging.info('Sending mail: recipient %r, subject %r' % (to, subject))
        try:
            mail.send_mail(sender=sender, subject=subject, to=to, body=body)
        except mail_errors.Error, e:
            # we swallow mail_error exceptions on send, since they're not ever
            # transient
            logging.error('EmailSender (to: %s, subject: %s), '
                          'failed with exception %s' % (to, subject, e)) 
Example #21
Source File: test_send_mail.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def test_email_fail(self):
        subject = 'test'
        to = 'bad_email_address'
        sender = 'me@example.com'
        body = 'stuff'
        mymox = mox.Mox()
        mymox.StubOutWithMock(logging, 'error')
        logging.error('EmailSender (to: %s, subject: %s), '
                      'failed with exception %s' % (to, subject, 'exception'))
        mymox.StubOutWithMock(mail, 'send_mail')
        mail.send_mail(sender=sender,
                       subject=subject,
                       to=to,
                       body=body).AndRaise(mail_errors.Error('exception'))
        handler = send_mail.EmailSender()
        repo = 'haiti'
        model.Repo(key_name=repo).put()
        request = webapp.Request(
            webob.Request.blank(
                '/admin/send_mail?to=%s&subject=%s&sender=%s' %
                (to, subject, sender)).environ)
        request.method = 'POST'
        request.body = 'body=%s' % body
        handler.initialize(request, webapp.Response())
        mymox.ReplayAll()
        handler.post()
        # shouldn't raise an error.
        assert True
        mymox.VerifyAll()