forked from kubernetes/release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer
executable file
·101 lines (96 loc) · 3.21 KB
/
mailer
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
#
# Copyright 2016 The Kubernetes Authors 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.
#
# Set PROGram name
PROG=${0##*/}
########################################################################
#+
#+ NAME
#+ $PROG - General (send)mail interface
#+
#+ SYNOPSIS
#+ $PROG --to=<address,address,...> --subject="..." --file=<file>
#+ [--html] [--cc=<address,address,...>] [--from=<address>]
#+ [--replyto=<address> ]
#+ $PROG [--helpshort|--usage|-?]
#+ $PROG [--help|-man]
#+
#+ DESCRIPTION
#+ Google has deprecated sendmail for internal use -- go/nosmtp.
#+ $PROG provides an common interface for sending email using a sendmail
#+ replacement (for use within Google).
#+
#+ $PROG by default sends plain text. Use --html to send html.
#+
#+ OPTIONS
#+ --to=<address,address,...> - space separated list of people to mail
#+ --subject="..." - mail subject
#+ --file=<file> - file to mail
#+ [--cc=<address,address,...>] - space separated list of people to cc
#+ [--replyto=<address>] - address to reply to
#+ [--from]=<address>] - From address
#+ [--html] - Send html content
#+ [--help | -man] - display man page for this script
#+ [--helpshort] - display gbash-usage
#+ [--usage | -?] - display in-line usage
#+
#+ EXAMPLES
#+ $PROG --to="$USER" --subject="This PASSED!" --file=/tmp/mailfile.23561
#+ - Mail the contents of /tmp/mailfile.23561
#+
#+ FILES
#+
#+ SEE ALSO
#+ common.sh - function definitions for timestamp, etc.
#+
#+ BUGS/TODO
#+
########################################################################
# If NO ARGUMENTS should return *usage*, uncomment the following line:
usage=${1:-yes}
source $(dirname $(readlink -ne $BASH_SOURCE))/lib/common.sh
if [[ $(hostname) =~ \.google\. ]]; then
# Quietly check for sendgmr
common::check_packages sendgmr || common::exit 1 "Exiting..."
# sendgmr doesn't do much checking so hold its hand and talk nicely to it
[[ -n "$FLAGS_cc" ]] && CC_ARG="-cc=$FLAGS_cc"
if ((FLAGS_html)); then
FILE_ARGS="--html_file=$FLAGS_file --body_file=/dev/null"
else
FILE_ARGS="--html_file=/dev/null --body_file=$FLAGS_file"
fi
# Send it!
sendgmr \
-to="$FLAGS_to" \
-from="$FLAGS_from" \
-reply_to="$FLAGS_replyto" \
-subject="$FLAGS_subject" \
$CC_ARG \
$FILE_ARGS
else
# Nice and simple
(
cat <<EOF+
To: $FLAGS_to
From: $FLAGS_from
Subject: $FLAGS_subject
Cc: $FLAGS_cc
Reply-To: $FLAGS_replyto
EOF+
((FLAGS_html)) && echo "Content-Type: text/html"
cat $FLAGS_file
) |/usr/sbin/sendmail -t
fi