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/

Sending Email from mailx Command in Linux Using Gmail’s SMTP的更多相关文章

  1. uva 10986 - Sending email(最短路Dijkstra)

    题目连接:10986 - Sending email 题目大意:给出n,m,s,t,n表示有n个点,m表示有m条边,然后给出m行数据表示m条边,每条边的数据有连接两点的序号以及该边的权值,问说从点s到 ...

  2. Sending e-mail with Spring MVC---reference

    reference from:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of con ...

  3. Using Android Phone to recover SD card formatted with DD command under linux

    Using Android Phone to recover SD card formatted with DD command under linux 1. Formatted a sd card ...

  4. screen command of linux

    [screen command of linux] 常用键:   补充: Ctrl-a S  # split terminal horizon Ctrl-a TAB   # switch to ano ...

  5. 下载tree命令的源代码 - The Tree Command for Linux Homepage

    The Tree Command for Linux Homepage http://mama.indstate.edu/users/ice/tree/ [root@test ~]# ll -as m ...

  6. Sending e-mail with Spring MVC--转载

    原文地址:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of contents: 1.S ...

  7. logrotate command in Linux

    背景 在生产过程中,由于磁盘空间.保留周期等因素,会对系统.应用等日志提出要求,要求系统日志定期进行轮转.压缩和删除,从而减少开销,而系统自带的logrotate  则是一个简单又实用的小工具,下面着 ...

  8. Changing the Color of Linux ls Command 改变Linux的ls命令显示的颜色

    Linux command ls basically use the file /etc/DIR_COLORS or /etc/DIR_COLORS.xterm to define the color ...

  9. Spring – Sending E-Mail Via Gmail SMTP Server With MailSender--reference

    Spring comes with a useful ‘org.springframework.mail.javamail.JavaMailSenderImpl‘ class to simplify ...

随机推荐

  1. Linux分区有损坏修复

    如果Linux分区有损坏情况,启动有问题,不能正常进入文本或图形界面.那么一般会出现提示,需要输入Root密码登录后采用fsck -t ext3 -r /usr/local 修复 , /usr/loc ...

  2. Web分布式部署,跨应用程序Forms身份验证的集成方案

    最近一个项目要求进行分布式部署.保证在双十一期间系统的正常运行,虽然该系统平时访问量不是很大,但是基于业务需要,必须在至少两台服务器上部署. 该系统需要登录后才可以使用,首先需要解决分布式部署的用户状 ...

  3. emoji表情符处理替换成空格

    /**    * 用filterOffUtf8Mb4    * Description: 过滤率四个字节的utf-8字符(emoji表情符),替换成四个空格.    *         四字节utf- ...

  4. VS2013 支持python和nodejs

    一.在VS2013中,安装python的支持 1. http://pytools.codeplex.com/下载插件 2. https://www.python.org/download/下载Pyth ...

  5. js和jQuery 获取屏幕高度、宽度

    js获取屏幕高度,宽带 网页可见区域宽:document.body.clientWidth网页可见区域高:document.body.clientHeight网页可见区域宽:document.body ...

  6. SQL Server之内连接 左连接 右连接 全连接 交叉连接

    SELECT * FROM Table_A GO SELECT * FROM Table_B GO --内连接 SELECT a.*, b.* FROM Table_A a JOIN Table_B ...

  7. 实战FFmpeg编译支持arm64(转)

    App store要求上架的app必须支持arm64.而手中的ffmpeg还不支持arm64, 百度下ffmpeg支持arm64方法,网上有很多资料.其中一篇是使用脚本自动编译实现的.本文就是使用它的 ...

  8. AI-->从新建文档开始说起,串联相关色彩知识

    相关概念:AI.PS.矢量图形 AI:  Adobe Illustrator 是Adobe公司出品的一款用于矢量图形设计的软件. 矢量图形:用通俗的大白话讲与分辨率无关,可以任意的放大缩小而不会失真图 ...

  9. sublime text 3 扩展插件SideBarEnhancements用法教程

    SideBarEnhancements本是增强侧边栏的插件,这里将教大家如何用来做sublime text 3浏览器预览插件,并可自定义浏览器预览的快捷键. 第一步:安装此插件,搜索相关教程,本博客有 ...

  10. 【ERROR】---Error executing "adb devices":ADB server didn't ACK

    搭建环境     ionic emulate android 的时候出现问题 端口占用,找到占用端口的程序,结束进程再启动 重新ionic emulate android 还是报错,闪了一下说fail ...