Linux scripts to automatically send and receive mail settings method _linux Shell

Source: Internet
Author: User
Tags imap mkdir
1. Send mail in command line mode
1.1 Installation SendEmail
2.2 Using SendEmail and examples

2. Command line mode of receiving mail
2.1 Installation Getmail4
2.2 Configuration Getmail4 and simple examples
2.3 Using Munpack to extract attachments from the message

1. Send mail in command line mode

1.1 Installation SendEmail
Under Ubuntu, you can search for the installation with the new software package Manager or run it at a terminal:
sudo apt-get install SendEmail
It is recommended that you install two additional packages before installation: Libio-socket-ssl-perl, Libnet-ssleay-perl

2.2 Using SendEmail and examples

If you want to use your email christ@gmail.com to send mail to buddha@qq.com, enter in the terminal:
Sendemail-s smtp.gmail.com-f christ@gmail.com-t buddha@qq.com-u hello-m "A Hello from Christans to Buddhists via Gmai L "-xu christ-xp password-o Tls=auto

Explain:
-S smtp.gmail.com Specify the server domain name, mail sent generally through the SMTP protocol, its domain name is generally smtp.***.com, such as QQ Mailbox server for smtp.qq.com,163 mailbox is smtp.163.com
-F christ@gmail.com Specify send mailbox address
-T buddha@qq.com specify destination mailbox address
-U Hello message header
-M "A Hello from Christans to Buddhists via Gmail" message body, the longer body can be in the text file first, may be named Mail.txt, then replace with-O message-file=mail.txt
-xu Christ Specify the mailbox username, that is, the part before the mailbox address @
-XP Password Specify the password to send a mailbox
-O Tls=auto encryption is automatically selected in None, TLS, SSL
If you want to paste attachments in a message
-A attachment_file1 attachment_file2 attachment_file3

2. Command line mode of receiving mail

There are two main ways to collect email messages via email clients: POP3 and IMAP, mail clients download messages on the server via POP3, but IMAP defaults to download only the subject of the message. Based on the meaning of command line automation, it is more suitable to adopt POP3.

2.1 Installation Getmail4

Under Ubuntu, you can search for the installation with the new software package Manager, or
sudo apt-get install Getmail4

2.2 Configuration Getmail4 and simple examples

Execute command at terminal after installation
Copy Code code as follows:

CD ~
mkdir. Getmail
CD. Getmail
mkdir Maildir
CD Maildir
mkdir NEW cur tmp


After the. getmail/to create a configuration file, if this profile is to collect buddha@qq.com this mailbox configuration, it may be named Getmailrc.buddha, and then edit the file, #后是注释:

Copy Code code as follows:

# This is a configuration the file for buddha@qq.com
[Retriever]
Type = Simplepop3retriever
Server = pop.qq.com #如果是gmail则改为pop. gmail.com
Username = Budda
Password = password

[Destination]
Type = Maildir
Path = Directory created by ~/.getmail/maildir/#就是刚才在 ~/.getmail/, note that there must be new,cur,tmp in this directory three subdirectories

[Options]
Read_all = False #只接受以前没有收取的邮件, and if changed to true, all messages in the mailbox will be charged
Delete = False #下载邮件后不在服务器上删除该邮件, and if changed to true delete

# configuration file ends here
After editing, run at the terminal:
Getmail--rcfile=getmailrc.buddha

Getmail will automatically receive mail, downloaded messages will be saved under ~/.getmail/maildir/new/.

2.3 Using Munpack to extract attachments from the message

The message body and attachment are saved as a whole file, attachments are attached in MIME format to the whole file and must be extracted by program.
Under Ubuntu, you can search for installation mpack with the new software package Manager, or sudo apt-get install MPack
Running in a terminal: Munpack mail_file
The program automatically identifies the attachment and extracts it.
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.