Created
January 20, 2020 18:52
-
-
Save kosmala007/7d901632ea36daf000f8e311cab0f869 to your computer and use it in GitHub Desktop.
Send email from bash by curl (UTF-8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# send email to one recipient (content in var) | |
# $host - eg. smtp.devpack.pl | |
# $port - 587 | |
# $user - admin@devpack.pl | |
# $pass - password | |
# $recipient - recipient | |
# $content - message content must hace headers | |
# $subject - message subject | |
content=$'From: <'$user$'l> \nTo: <'$recipients$'> \nContent-Type: text/plain;charset=utf-8 \nSubject: '$subject$'\n\n' | |
curl --connect-timeout 15 -v --insecure "smtp://$host:$port" \ | |
-u "$user:$pass" \ | |
--mail-from "$user" \ | |
--mail-rcpt "$recipient" \ | |
-T - \ | |
--ssl \ | |
<<< "$content" | |
# send email to multiple recipients (content in var) | |
# $recipients - email addreses divided by coma eg: 'eamil1@fancybox.pl,eamil2@fancybox.pl' | |
content=$'From: <'$user$'l> \nTo: <'$recipients$'> \nContent-Type: text/plain;charset=utf-8 \nSubject: '$subject$'\n\n' | |
curl --connect-timeout 15 -v --insecure "smtp://$host:$port" \ | |
-u "$user:$pass" \ | |
--mail-from "$user" \ | |
$(echo "${recipients}" | tr ', ' '\n' | xargs -r -n1 printf '--mail-rcpt %s ') \ | |
-T - \ | |
--ssl \ | |
<<< "$content" | |
# send email (content in file) | |
# $pathToFile - path to file | |
curl --connect-timeout 15 -v --insecure "smtp://$host:$port" \ | |
-u "$user:$pass" \ | |
--mail-from "$user" \ | |
--mail-rcpt "$recipient" \ | |
-T "$pathToFile" \ | |
--ssl \ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment