zoukankan      html  css  js  c++  java
  • Sending Email from mailx Command in Linux Using Gmail’s SMTP

    The mailx or mail command in Linux is still providing service for guys like me, especially when we need to send email automatically by script. gmail is great. Now, how to use gmail’s smtp in mailx/mail? gmail is a little special since gmail’s smtp server requires tls authorization. The good news is that mailx supports it. Let’s look at how to use it.

    First, find out Fixforx’s profile directory in the home directory (I believe most of the users on Linux use Firefox. If you are not using Firefox, what you need to do is try it ;) . It has a format like this:

    ~/.mozilla/firefox/yyyyyyyy.default

    yyyyyyyy is a random string that’s different for different users. You can easily find it out by looking into the directory ~/.mozilla/firefox.

    There are two ways to do this: using all-in-one command or putting configurations into profile. The all-in-one-command way needs no other configurations except the command line itself, while the way using configuration has a clearer command.

    All-in-one command

    This is an all-in-one command that sends email to $TO_EMAIL_ADDRESS

    mailx -v -s "$EMAIL_SUBJECT"-S smtp-use-starttls
    -S ssl-verify=ignore
    -S smtp-auth=login
    -S smtp=smtp://smtp.gmail.com:587-S from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)"-S smtp-auth-user=$FROM_EMAIL_ADDRESS
    -S smtp-auth-password=$EMAIL_ACCOUNT_PASSWORD
    -S ssl-verify=ignore
    -S nss-config-dir=~/.mozilla/firefox/yyyyyyyy.default/
    $TO_EMAIL_ADDRESS

    Replace the $XXX with the value that is actually used. The meaning is obvious. And remember to change yyyyyyyy to the string that’s part of the Firefox profile directory.

    This command will ask for the email content. Type in the mail content and after finishing the email, use “Ctrl+d” to tell mailx you have finished. Then this mail will be sent out through gmail’s smtp server. You can also use pipe like this:

    echo "The mail content"| mail -v -s ...

    Use configuration file

    There are too many options in the above command? Yes… I must confess so. We can write most of them into mailx/mail’s configuration file ~/.mailrc

    set smtp-use-starttls
    set nss-config-dir=~/.mozilla/firefox/yyyyyyyy.default/set ssl-verify=ignore
    set smtp=smtp://smtp.gmail.com:587set smtp-auth=login
    set smtp-auth-user=$FROM_EMAIL_ADDRESS
    set smtp-auth-password=$EMAIL_ACCOUNT_PASSWORD
    setfrom="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)"

    Change the $YYYY and yyyyyyyy to the right value for you. When sending mails, use this command:

    $ mailx -v -s "$EMAIL_SUBJECT" $TO_EMAIL_ADDRESS

    Then, time to enjoy it!

    From: http://www.fclose.com/1411/sending-email-from-mailx-command-in-linux-using-gmails-smtp/

    =================================================================

    如果没有使用firefox的话,可以尝试搜索 find /etc -name "cert*.db" ,结果例如:/etc/pki/nssdb/

    以下是腾讯企业邮箱的配置示例:

    set from=XXX@domain.com(MyName)
    set smtp=smtp.exmail.qq.com
    set smtp-auth-user=XXX@domain.com
    set smtp-auth-password=*****
    set smtp-auth=login
    set ssl-verify=ignore
    set nss-config-dir=/etc/pki/nssdb/
  • 相关阅读:
    希尔排序-Python
    顺序表为什么要在定义时分配空间大小
    pip install -r requirements.txt安装问题
    python小白系列2—python常用工具:pycharm
    python小白系列1—python安装,初识Anaconda
    Python Traceback模块:捕获更详细的异常报错信息
    pycharm项目中的.idea文件夹是干什么用的?可以删除吗?
    python多线程使用
    《统计学习方法》自学笔记—1.概论
    JAVA项目中的常用的异常处理情况
  • 原文地址:https://www.cnblogs.com/toby/p/3622753.html
Copyright © 2011-2022 走看看