You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7 KiB

  1. #!/usr/bin/env sh
  2. #Support sendmail
  3. #SENDMAIL_BIN="sendmail"
  4. #SENDMAIL_FROM="yyyy@gmail.com"
  5. #SENDMAIL_TO="yyyy@gmail.com"
  6. sendmail_send() {
  7. _subject="$1"
  8. _content="$2"
  9. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  10. _debug "_subject" "$_subject"
  11. _debug "_content" "$_content"
  12. _debug "_statusCode" "$_statusCode"
  13. SENDMAIL_BIN="${SENDMAIL_BIN:-$(_readaccountconf_mutable SENDMAIL_BIN)}"
  14. if [ -z "$SENDMAIL_BIN" ]; then
  15. SENDMAIL_BIN="sendmail"
  16. _info "The SENDMAIL_BIN is not set, so use the default value: $SENDMAIL_BIN"
  17. fi
  18. if ! _exists "$SENDMAIL_BIN"; then
  19. _err "Please install sendmail first."
  20. return 1
  21. fi
  22. _saveaccountconf_mutable SENDMAIL_BIN "$SENDMAIL_BIN"
  23. SENDMAIL_FROM="${SENDMAIL_FROM:-$(_readaccountconf_mutable SENDMAIL_FROM)}"
  24. if [ -z "$SENDMAIL_FROM" ]; then
  25. SENDMAIL_FROM="$USER@$HOSTNAME"
  26. _info "The SENDMAIL_FROM is not set, so use the default value: $SENDMAIL_FROM"
  27. fi
  28. _saveaccountconf_mutable SENDMAIL_FROM "$SENDMAIL_FROM"
  29. SENDMAIL_TO="${SENDMAIL_TO:-$(_readaccountconf_mutable SENDMAIL_TO)}"
  30. if [ -z "$SENDMAIL_TO" ]; then
  31. SENDMAIL_TO="$(_readaccountconf ACCOUNT_EMAIL)"
  32. _info "The SENDMAIL_TO is not set, so use the account email: $SENDMAIL_TO"
  33. fi
  34. _saveaccountconf_mutable SENDMAIL_TO "$SENDMAIL_TO"
  35. subject="=?UTF-8?B?$(echo "$_subject" | _base64)?="
  36. error=$( { echo "From: $SENDMAIL_FROM
  37. To: $SENDMAIL_TO
  38. Subject: $subject
  39. Content-Type: text/plain; charset=utf-8
  40. $_content
  41. " | "$SENDMAIL_BIN" -f "$SENDMAIL_FROM" "$SENDMAIL_TO"; } 2>&1 )
  42. if [ $? -ne 0 ]; then
  43. _debug "sendmail send error."
  44. _err "$error"
  45. return 1
  46. fi
  47. _debug "sendmail send success."
  48. return 0
  49. }