Linux uses mail to send external SMTP mail

Source: Internet
Author: User
Tags auth bz2

Description
Linux's own mail can implement external SMTP mail. There is no need to configure the Postfix,sendmail mail server locally, it does take a bit of time to configure the package.

Realize:
1. Turn off the SendMail service or postfix service of this machine

The code is as follows Copy Code

SendMail
# Service SendMail Stop
# chkconfig SendMail off

Postfix
# service Postfix Stop
# chkconfig Postfix off

2. Modify/etc/mail.rc, add a bit like n line, specify external SMTP server address, account password, etc.

The code is as follows Copy Code
# cp/etc/mail.rc/etc/mailrc.bak.20131113
# Cat/etc/mail.rc//content as follows
Set from=123456@qq.com
Set smtp=smtp.qq.com
Set smtp-auth-user=123456
Set SMTP-AUTH-PASSWORD=SBSBSBSB
Set Smtp-auth=login

3. Then send the message by command

The code is as follows Copy Code
# echo Hello Word | Mail-s "title" 123456@qq.com

There is no problem sending mail under RHEL6. But under the RHEL5, has not been able to send. What is this for? You can look at the difference between mail and MAILX under RHEL6 and RHEL5.
RHEL6 under

The code is as follows Copy Code
# Rpm-qa|grep MAILX
Mailx-12.4-6.el6.x86_64
# ll/bin/mail*//mail link to mailx,mailx version 12.4
lrwxrwxrwx. 1 root 5 July 2011/bin/mail-> MAILX
-rwxr-xr-x. 1 root root 390424 February 2010/bin/mailx
# mail-v
12.4 7/29/08

RHEL5, we found some different

The code is as follows Copy Code
# Rpm-qa|grep MAILX
mailx-8.1.1-44.2.2
# ll/bin/mail*//MAILX link to mail command, MAILX version 8.1
-rwxr-xr-x 1 root Mail 84856 June 6 2007/bin/mail
lrwxrwxrwx 1 root 4 Apr 18:03/bin/mailx-> Mail
# mail-v

There is an error in running here, no-V, which means that under RHEL65, running mail and MAILX is actually a command, and the mail version is different, causing the RHEL5 Mail command to not invoke the external SMTP server. Therefore, installing a new version of MAILX can resolve this issue.

1.rhel5 install a new version Mailx

The code is as follows Copy Code
# wget FTP://FTP.SPLINE.INF.FU-BERLIN.DE/PUB/GENTOO/DISTFILES/MAILX-12.4.TAR.BZ2// Download mailx-12.4.tar.bz2, more download address http://www.filewatcher.com/m/mailx-12.4.tar.bz2.271482.0.0.html
# tar JXVF mailx-12.4.tar.bz2
# CD mailx-12.4
# make
# Make Install Ucbinstall=/usr/bin/install
# Whereis MAILX//view MAILX program default installation location, and version
MAILX:/usr/local/bin/mailx/usr/share/man/man1p/mailx.1p.gz
# mailx-v

12.4 7/29/08
2. Modify the/etc/nail.rc, after the installation of the MAILX use is/etc/nail.rc rather than/etc/mail.rc. This needs attention,!!!.

The code is as follows Copy Code
# vi/etc/nail.rc//Line end add like downlink
Set from=123456@qq.com
Set smtp=smtp.qq.com
Set smtp-auth-user=123456
Set SMTP-AUTH-PASSWORD=SBSBSBSB
Set Smtp-auth=login

2. Then send the message by command

  code is as follows copy code

# echo   Hello Word | Mailx-v-S "title" 123456@qq.com  //successfully sent, you can see a similar hint
 235 2.7.0 authentication successful   >>> MAIL from:<demo@qq.com> 
 250 2.1.0 ok 
 >>> RCPT to:& lt;xxxxx@qq.com> 
 250 2.1.5 ok 
 >>> data 
 354 end DATA with &L T cr><lf>.<cr><lf> 
 >>> . 
 250 2.0.0 ok:queued as 9291963494 
 >>> quit 
 221 2.0.0 bye 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.