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. Android 常用 adb 命令

    查看原文:http://blog.csdn.net/u010818425/article/details/52266593 (一)基础操作 安装app adb install -r xxx.apk / ...

  2. 通过maven添加quartz

    pom.xml中相关dependency信息 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <depen ...

  3. 条件控制(if ) ( case)

    一:IF应用格式 (1) (2) (3) IF 条件 THEN IF 条件 THEN IF 条件1 THEN --代码块        --代码块    --代码块1 commit; commit; ...

  4. SharePoint 2010 配置基于MemberShip的身份验证

    场景:通常需要为sharepoint打通其他的系统整合到sharepoint认证,ad通常是为内部域用户,外网访问的可以使用membership来登录,那么这个既可以内部用户访问,外部用户也可以访问 ...

  5. js中关于数据类型的转换

    * 一.转化为数字*/console.log(‘123123’*1.0); /* 二.从一个值中提取另一中类型的值,并完成转化工作 */console.log(parseInt(‘1233zxhag’ ...

  6. 常用的Linux系统调用命令

    常用的Linux系统调用命令   下面一些函数已经过时,被新的更好的函数所代替了(gcc在链接这些函数时会发出警告),但因为兼容的原因还保留着,这些函数将在前面标上“*”号以示区别.   一.进程控制 ...

  7. How Old Are You?

    今天要分享的是一个测年龄的小应用,就类似是http://how-old.net官网测年龄的功能一样,我的也是这样一个功能,细节捕获当然没有how-old多啦,不过这些主要是基于一个第三方的jar包,我 ...

  8. 在sql-server上建立mysql链接库

    EXEC sp_addlinkedserver @server = N'RESUME_MYSQL_CONN', @srvproduct=N'MySQL ODBC 5.1 Driver', @provi ...

  9. C# 操作 Excel 常见问题收集和整理(定期更新,欢迎交流)

    经常会有项目需要把表格导出为 Excel 文件,或者是导入一份 Excel 来操作,那么如何在 C# 中操作 Excel 文件成了一个最基本的问题. 做开发这几年来,陆陆续续也接触过这样的需求,但因为 ...

  10. 怎么解决tomcat占用8080端口问题图文教程(转)

    亲测有效. 原因:可能是开了多个tomcat 原文网址:http://jingyan.baidu.com/article/1612d5006c3cdae20e1eee04.html  怎么解决tomc ...