linux - 通过 Cygwin 发送电子邮件

标签 linux shell cygwin sh email-client

我写了一个 shell 脚本,我想通过它发送电子邮件。我通过 cygwin 在 Windows 上执行这个脚本。我已经在我的机器上安装了电子邮件包。然而,我很难让它发挥作用。请让我知道通过 cygwin 命令提示符发送电子邮件的最简单方法是什么。

我的 ssmtp.conf 文件是:

mailhub=smtp.gmail.com:587
FromLineOverride=YES
rewriteDomain=gmail.com
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87f5e8e8f3bae6e4eea9ebe1eee9e3e5e6c7e0eae6eeeba9e4e8ea" rel="noreferrer noopener nofollow">[email protected]</a>
UseTLS=YES
AuthUser=userid
AuthPass=password

email.conf 文件有:

SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = '25'
MY_NAME  = 'ABC'
MY_EMAIL = 'emailaddress'
REPLY_TO = 'emailaddress'
USE_TLS = 'true'
ADDRESS_BOOK = '&/email.address.template'
SMTP_AUTH = 'LOGIN'
SMTP_AUTH_USER = 'userid'
SMTP_AUTH_PASS = 'password'

我正在使用以下命令发送电子邮件: echo“邮件正文”|电子邮件-s“主题”[email protected] 但是,我收到以下错误: 电子邮件:致命:无法连接到服务器:smtp.gmail.com,端口:25:不允许操作

请帮忙。

最佳答案

安装并配置ssmtp包。

使用以下内容创建 /bin/mail:

#!/bin/sh
#
# copyright 2016 Gene Pavlovsky [http://www.razorscript.com]
#
# mail: mail-like wrapper script for sendmail

SENDMAIL=/usr/sbin/ssmtp

usage()
{
  {
    echo "Usage: $(basename $0) [-s "subject"] [-f from-addr] [to-addr]..."
    echo
    echo "Sends mail."
    echo
    echo "Options:"
    echo -e "  -s\tsubject (quote subjects containing spaces)"
    echo -e "  -f\tfrom address"
  } >&2
  exit 2
}

while test $# -gt 0; do
  case $1 in
    -s)
            shift
            test $# -eq 0 && usage
            subj=$1
    ;;
    -f)
            shift
            test $# -eq 0 && usage
            from=$1
    ;;
    -*)
      usage
    ;;
    *)
            rcpt+=( "$1" )
    ;;
  esac

  shift
  test "$end_options" = yes && break
done

test ${#rcpt} -eq 0 && usage

{
    test "$from" && echo From: $from
    test "$subj" && echo Subject: $subj
    echo
    exec /bin/cat
} | "$SENDMAIL" "${rcpt[@]}"

不要忘记chmod 755/bin/mail

关于linux - 通过 Cygwin 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16017311/

相关文章:

linux - 弄错路径,失败并返回 "No rule to make target"

linux - 为什么更频繁地读取磁盘会使 Linux 上的每次读取速度更快? QPS1 对比 50

linux - 如何使用 ssh 连接到随机临时服务器而不提示密码

ruby - Chef shell 脚本未运行

c - 在 Eclipse Kepler 中运行 *.c 文件时出错

python - 我怎么知道我的 python 脚本是否正在运行? (使用 Cygwin 或 Windows shell )

linux - 关于软件桥连接问题的债券

mysql - 在 Sql Server 2008 上链接 MySQL 服务器

shell - Ubuntu shell 脚本不工作

c++ - cygwin 上的 g++ 与我在 Linux 平台上获得的有什么不同吗?