注册 登录
编程论坛 Linux教室

命令行中发送Gmail 邮件,大家快去试试吧(教程)

madfrogme 发布于 2012-10-06 23:44, 2061 次点击
命令行里面用gmail发邮件的方法终于搞出来了,
 
哈哈,下面只说简单必要的步骤
 
1. 须要两个软件 msmtp 和heirloom-mailx
 
# aptitude install msmtp heirloom-mailx
 
2. 希望你的ubuntu 下有 /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt 这个文件
 
3. 建立 ~/.msmtprc  
 
# Gmail account starts
 
# account name which must be unique for each account
 
account gmail1
 
auth on
 
#Gmail SMTP host name
 
host smtp.
 
port 587
 
#sets Transport Layer Security on
 
tls on
 
# location of tls certificate file for Gmail (change this parameter if your certificate file is stored at some other location in your File-system)
 
tls_trust_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt
 
#your email id here (e.g. abc@)
 
user YOUR_EMAIL_ID
 
#your password here
 
password YOUR_PASSWORD
 
#email id of the sender that is you again
 
from YOUR_EMAIL_ID
 
# Gmail account end
 
#So we have added one account. Similarly we can add more accounts by repeating and modifying  
 
#above code for each new account. Make sure you give unique name to each account.
 
#set default account to be used when no account is specified (Not necessary for single account)
 
account default: gmail1
 
复制粘贴,大写字母的三个地方修改一下,
 
4. 改一下权限
 
$ chmod 600 ~/.msmtprc
 
5. 再建立一个文件 ~/.mailrc
 
set from="YOUR_EMAIL_ID"                    #your email id here
 
set sendmail="/usr/bin/msmtp"       #location of msmtp's binary executable
 
set message-sendmail-extra-arguments="-a gmail1"  
 
#additional arguments to msmtp goes here (optional) (-a indicates account name to be used to send mails)
 
复制粘贴, 大写字母的地方改一下
 
6. 好了,可以发在命令行发邮件了
 
$ mailx ***@***            这是我的手机地址,接受骚扰
 
会提示主题
 
写玩内容后按Ctrl-D 发送, 成功了吧,功了吧,了吧,吧~~~~


[ 本帖最后由 madfrogme 于 2012-11-1 18:48 编辑 ]
7 回复
#2
madfrogme2012-10-06 23:50
顺便说一下,

$ mailx -a ~/file   ***@

可以添加附件file

-s  可以指定主题,还可以把内容重定向

mailx -s "主题"  ***@**.com < /file


[ 本帖最后由 madfrogme 于 2012-10-7 00:52 编辑 ]
#3
zklhp2012-10-07 00:26
77是年龄么 大哥您好
#4
madfrogme2012-10-07 00:33
以下是引用zklhp在2012-10-7 01:26:28的发言:

77是年龄么 大哥您好

初始的地址,开始不知道怎么改,告诉别人之后就懒得改了,77你也该叫我大爷了,
#5
遗矢的老人2012-10-07 01:22
学习
#6
pangding2012-10-07 05:59
学习
#7
有容就大2012-10-07 19:21
厉害
#8
小习小习2012-10-07 22:30
膜拜
1