shell 群发邮件
最近由于公司业务需要,需要群发邮件,做推广。
 
方法一、
脚本如下:
InBlock.gif#!/bin/sh
InBlock.gifwhile read rad
InBlock.gifdo
InBlock.gifmail -s "邮件标题" $rad < abc.txt
InBlock.gifdone < mail.txt
abc.txt为邮件内容
mail.txt为邮件列表,如下所示
InBlock.gif abc@qq.com  
InBlock.gifdef@sohu.com 
InBlock.gif........
 
注意:为了使邮件支持中文,得设置一下系统环境变量
InBlock.gif[root@ws ~]# cat /etc/sysconfig/i18n    
InBlock.gifLANG="zh_CN"
LANG="zh_CH"
方法二、
yum install mutt
 
脚本如下:
InBlock.gif#!/bin/sh    
InBlock.gif i=1
InBlock.gif while read rad    
InBlock.gif do    
InBlock.gifcat abc.txt | mutt -s "邮件标题" $rad    
InBlock.gif    echo no.$i              #加一个计数器,查看发送了多少封mail
InBlock.gif    ((i+=1))
InBlock.gifdone < mail.txt
abc.txt为邮件内容
mail.txt为邮件列表
注意:为了使邮件支持中文,得设置一下系统环境变量
InBlock.gif[root@ws ~]# cat /etc/sysconfig/i18n    
InBlock.gifLANG="en_US.UTF-8"
InBlock.gifSYSFONT="latarcyrheb-sun16"
ssh客户端编码最好设置成为utf-8编码
 
 
让mutt发送邮件支持html
 
InBlock.gifcat abc.txt | mutt -s "邮件标题" -e "my_hdr content-type:text/html" $rad
 
只需要在mutt后边带上-e "my_hdr content-type:text/html" 就可以了
 
怎样才能让我发出的信件使用我的POP邮箱的地址,而不是 root@myhost.com 这样的地址?
用 my_hdr 把你的 From: 设置为你想要的地址就行了。比如我是这样设置的:
my_hdr From: wang-y01@mails.tsinghua.edu.cn
 
通过mutt与msmtp认证群发邮件
1)下载msmtp

msmtp下载地址 
http://downloads.sourceforge.net
2)解压:

tar jxvf msmtp-1.4.16.tar.bz2

3)安装:

./configure --prefix=/usr/local/msmtp

make

make install

4) 配置 msmtp账号:

新建文件/usr/local/msmtp/etc/msmtprc

编辑内容:

# Set default values for all following accounts.

defaults

# The SMTP server of the provider.

account test

host 发送邮件服务器名称

from 发送的邮件Email

auth login

user 邮件服务器登录账号

password 邮件服务器登陆密码

# Set a default account

account default : test

5)保存退出,测试客户端是否可用

/usr/local/smtp/bin/msmtp 目标邮件地址

随便输入一些字符,然后按ctrl+D退出,去目标邮件地址查看邮件是否收到。

6)配置mutt,mutt一般linux都会默认安装,可以使用which mutt查看mutt安装的路径。

编辑mutt配置文件:/etc/Muttrc,修改一下几行:

set sendmail="/opt/msmtp/bin/msmtp"

set use_from=yes

set realname="发送邮件地址"

set editor="vi"

7)保存退出,测试一下mutt是否有效:

echo "测试测试" | mutt -s "测试" 测试邮件地址