[root@localhost /]# mail -s "Message" xxxxx@163.com < /tmp/info.message
系统默认以“root@主机名” 发送邮件,收到邮件直接被过虑成垃圾邮件了,那可不可以自定义邮箱发送邮件呢?
答案肯定可以的。
下载mailx包
mailx官方站点 http://heirloom.sourceforge.net/
下载最新版本mailx-12.4.tar.bz2 (271.5 kB)
http://sourceforge.net/projects/heirloom/files/latest/download?source=files
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
26
27
28
29
30
31
32
33
34
35
|
[root@localhost software]
# tar -jxvf mailx-12.4.tar.bz2
[root@localhost software]
# cd mailx-12.4
[root@localhost mailx-12.4]
# make
openssl.c:108: 错误:expected declaration specifiers or ‘...’ before ‘STACK’
openssl.c: 在函数‘ssl_select_method’中:
openssl.c:215: 警告:赋值丢弃了指针目标类型的限定
openssl.c:217: 警告:赋值丢弃了指针目标类型的限定
openssl.c:219: 警告:赋值丢弃了指针目标类型的限定
openssl.c:223: 警告:赋值丢弃了指针目标类型的限定
openssl.c:226: 警告:赋值丢弃了指针目标类型的限定
openssl.c: 在函数‘ssl_check_host’中:
openssl.c:311: 错误:‘STACK’未声明(在此函数内第一次使用)
openssl.c:311: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
openssl.c:311: 错误:所在的函数内也只报告一次。)
openssl.c:311: 错误:‘gens’未声明(在此函数内第一次使用)
openssl.c: 在文件层:
openssl.c:499: 错误:expected declaration specifiers or ‘...’ before ‘STACK’
openssl.c: 在函数‘smime_verify’中:
openssl.c:508: 错误:‘STACK’未声明(在此函数内第一次使用)
openssl.c:508: 错误:‘certs’未声明(在此函数内第一次使用)
openssl.c:508: 错误:‘gens’未声明(在此函数内第一次使用)
openssl.c:555: 错误:‘chain’未声明(在此函数内第一次使用)
openssl.c: 在函数‘cverify’中:
openssl.c:617: 错误:‘STACK’未声明(在此函数内第一次使用)
openssl.c:617: 错误:‘chain’未声明(在此函数内第一次使用)
openssl.c:649: 错误:提供给函数‘smime_verify’的实参太多
openssl.c: 在函数‘smime_encrypt’中:
openssl.c:690: 错误:‘STACK’未声明(在此函数内第一次使用)
openssl.c:690: 错误:‘certs’未声明(在此函数内第一次使用)
openssl.c: 在函数‘smime_certsave’中:
openssl.c:953: 错误:‘STACK’未声明(在此函数内第一次使用)
openssl.c:953: 错误:‘certs’未声明(在此函数内第一次使用)
openssl.c:955: 错误:‘chain’未声明(在此函数内第一次使用)
Makefile:80: recipe
for
target
'openssl.o'
failed
make
: *** [openssl.o] Error 1
|
出现错误,看下面文档帮助
http://www.linuxfromscratch.org/blfs/view/stable/basicnet/mailx.html
原来差补丁,修复他
1
2
3
4
|
[root@localhost mailx-12.4]
# wget http://www.linuxfromscratch.org/patches/blfs/7.6/mailx-12.4-openssl_1.0.0_build_fix-1.patch
[root@localhost mailx-12.4]
# patch -Np1 -i mailx-12.4-openssl_1.0.0_build_fix-1.patch
patching
file
makeconfig
patching
file
openssl.c
|
#修复补丁成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@localhost mailx-12.4]
# make clean #清除历史编译后文件
[root@localhost mailx-12.4]
# make #再次编绎
[root@localhost mailx-12.4]
# make install UCBINSTALL=/usr/bin/install
/usr/bin/install
-c mailx
/usr/local/bin/mailx
strip
/usr/local/bin/mailx
test
-d
/usr/local/share/man/man1
||
mkdir
-p
/usr/local/share/man/man1
/usr/bin/install
-c -m 644 mailx.1
/usr/local/share/man/man1/mailx
.1
test
-d
/etc
||
mkdir
-p
/etc
test
-f
/etc/nail
.rc || \
/usr/bin/install
-c -m 644 nail.rc
/etc/nail
.rc
[root@localhost bin]
# vim /etc/nail.rc #编辑nail.rc配置外部SMTP信息
set
from=xxxx@163.com smtp=smtp.163.com
set
smtp-auth-user=xxxxx@163.com smtp-auth-password=xxxxx smtp-auth=login
[root@localhost mailx-12.4]
# service postfix reload #重新加载postfix,可以不用重启的。
|
测试一下
1
|
[root@localhost mailx-12.4]
# mail -s "Message" xxxxx@163.com < /tmp/info.message
|
邮件发送成功,但为什么收到的还是root@localhost.xx发送的邮件呢?
1
2
|
[root@localhost mailx-12.4]
# whereis mailx
mailx:
/bin/mailx
/usr/bin/mailx
/usr/local/bin/mailx
/usr/share/man/man1/mailx
.1
/usr/share/man/man1/mailx
.1.gz
/usr/share/man/man1p/mailx
.1p.gz
|
哦,原因是新安装的包没有生效,执行还是原来的路径,替换他。
1
2
3
4
5
|
[root@localhost mailx-12.4]
# cd /bin
[root@localhost bin]
# rm -rf mailx
[root@localhost bin]
# ln -s /usr/local/bin/mailx mailx
[root@localhost bin]
# mailx -V
[root@localhost bin]
# mail -s "Message" xxxxx@163.com < /tmp/info.message
|
这下成功。
其它方法如:SendEmail 见 http://caspian.dotconf.net/menu/Software/SendEmail/
转载于:https://blog.51cto.com/beijixing/1897397