-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbash-curl-zerosmtp.sh
More file actions
50 lines (43 loc) · 1.56 KB
/
Copy pathbash-curl-zerosmtp.sh
File metadata and controls
50 lines (43 loc) · 1.56 KB
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
#!/bin/bash
# bash-curl-zerosmtp.sh
# Bash curl 8.10+ - ZeroSMTP mx.msgwing.com:465 SSL/TLS
# Production-ready | Let's Encrypt | POSIX heredoc
set -euo pipefail
error_exit() {
printf 'ERROR: %s\n' "$1" >&2
exit 1
}
trap 'error_exit "Script interrupted"' INT TERM
# Configuration from environment variables
# NOTE: names are prefixed with ZEROSMTP_ to avoid colliding with
# reserved/OS-level variables (e.g. USERNAME is auto-set on Windows).
USERNAME="${ZEROSMTP_USERNAME:-your-username}"
PASSWORD="${ZEROSMTP_PASSWORD:-your-password}"
FROM="${ZEROSMTP_FROM:-sender@example.com}"
TO="${ZEROSMTP_TO:-recipient@example.com}"
SUBJECT="${ZEROSMTP_SUBJECT:-Test Email from ZeroSMTP}"
# Validate inputs
[[ -z "$USERNAME" ]] && error_exit "ZEROSMTP_USERNAME not set"
[[ -z "$PASSWORD" ]] && error_exit "ZEROSMTP_PASSWORD not set"
[[ -z "$FROM" ]] && error_exit "ZEROSMTP_FROM not set"
[[ -z "$TO" ]] && error_exit "ZEROSMTP_TO not set"
# Build email body
EMAIL_BODY="From: $FROM\r\nTo: $TO\r\nSubject: $SUBJECT\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\nHello from ZeroSMTP! This is plain text sent via mx.msgwing.com:465"
# Send via curl with system CA verification
if curl \
--url "smtps://mx.msgwing.com:465" \
--user "$USERNAME:$PASSWORD" \
--mail-from "$FROM" \
--mail-rcpt "$TO" \
--upload-file <(printf '%b' "$EMAIL_BODY") \
--ssl-reqd \
--tlsv1.2 \
--connect-timeout 10 \
--max-time 30 \
--silent \
--show-error; then
printf 'Email sent successfully via ZeroSMTP\n'
exit 0
else
error_exit "Failed to send email via ZeroSMTP"
fi