forked from google/appengine-phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_mail.py
46 lines (41 loc) · 1.81 KB
/
send_mail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Python CLI for sending email. Currently does not handle attachments
from google.appengine.api import mail
import click
import logging
import json
import os
'''The below statements are required because we are not using the standard python runtime
This will be fixed in the next launch but we have to live with it for now'''
from google.appengine.ext.vmruntime import vmconfig
from google.appengine.ext.vmruntime import vmstub
vmstub.Register(vmstub.VMStub(vmconfig.BuildVmAppengineEnvConfig().default_ticket))
vmstub.app_is_loaded = True
@click.command()
@click.option('--to', help='users to receive the email')
@click.option('--email_subject', help='email subject to be sent to users')
@click.option('--email_body', help='email body to be sent to users')
@click.option('--cc', help='cc users to receive the email')
def send_mail(to, email_subject, email_body, cc):
application_id = os.environ.get('GAE_LONG_APP_ID')
message = mail.EmailMessage(sender="[email protected]", subject=email_subject)
message.sender = "noreply@" + application_id + ".appspotmail.com"
message.to = json.loads(to)
message.body = email_body
if cc:
message.cc = json.loads(cc)
message.send()
if __name__ == '__main__':
send_mail()