Install and configure sendmail in Ubuntu, using tusendmail
Because the project requires an email server function and there are various restrictions on using the existing enterprise mailbox, it is a great deal of related things. Generally, there are several options, such as Postfix, sendmail, and qmail. I used the first one before, but the project only needs to send emails, and somehow I chose sendmail. It turns out that I still don't want to do it, I will summarize some of my experiences and hope that you will be able to step down.
I. Installation
Required:
- Sudo apt-get install sendmail
- Sudo apt-get install sendmail-cf
- Sudo apt-get install mailutils
Optional:
- Squirrelmail // provides webmail
- Spamassassin // provides Email filtering.
- Mailman // provides support for the mail list
- Dovecot // provides the IMAP and POP receiving email server daemon process
- Sharutils // provides the function with attachments
Terminal input command: ps aux | grep sendmail
The output is as follows:
Root 20978 0.0 0.3 8300 1940? Ss sendmail: MTA: accepting connections
Root 21711 0.0 0.1 3008 776 pts/0 S + grep sendmail
It indicates that sendmail has been installed successfully and started.
Ii. Configuration
(1)/etc/mail/sendmail. mc
(A) configure sendmail to connect to any server
DAEMON_OPTIONS ('family = inet, Name = MTA-v4, Port = smtp, Addr = 127.0.0.1 ') dnl modify Addr = 0.0.0.0
(B) Add auth configuration (note that the character string is not a single quotation mark, but a symbol on the wave key in the keyboard)
TRUST_AUTH_MECH ('external DIGEST-MD5 CRAM-MD5 login plain ') dnl
Define ('confauth _ MECHANISMS ', 'external GSSAPI DIGEST-MD5 CRAM-MD5 login plain') dnl
(C) Enable access_db and trust_users
Add FEATURE (use_ct_file)
Modify FEATURE ('Access _ db', 'skip') dnl to FEATURE ('Access _ db') dnl
(2)/etc/mail/access
Add the IP address of the email server to the file in the following format: Connect: your_ip RELAY
Then update access_db: makemap hash/etc/mail/access. db </etc/mail/access
(3)/etc/mail/trusted-users
Add the IP address of the email server to the file in the following format:
Finally, a new configuration file is generated:
- Cd/etc/mail
- Mv sendmail. cf sendmail. cf ~ // Make a backup
- M4 sendmail. mc> sendmail. cf //> is left or right with a space. The system prompts that the sendm is not installed due to an error.
To prevent other email servers from putting emails into Spam, you can add an spf record by adding a TXT record in the domain name DNS management. The content is similar
"V = spf1 ip4: 67.202.107.106-all", modify/etc/host at the same time, add the mail server domain name and host name after 127.0.0.1 localhost
Iii. Test
(1) local test
1. General mail: mail test@126.com Cc edit Cc object, Subject: mail Subject, Enter, mail body, press Ctrl-D to end
2. Fast sending method: echo mail body | mail-s mail subject test@126.com
3. Send the mail as the body of the mail: mail-s test test@126.com <test.txt
4. send an email with an attachment: uuencode attachment name: attachment display name | mail-s mail subject sending Address
Example: uuencode test.txt | mail-s Test test@126.com
(2) Other machine tests
#-*-Coding: UTF-8 -*-
Import smtplib
From email. mime. text import MIMEText
From email. mime. multipart import MIMEMultipart
If _ name _ = "_ main __":
To = "to email addr"
Me = "your email addr"
Content = "test"
Msg = MIMEMultipart ('alternative ')
Msg ['subobject'] = "test"
Msg ['from'] = me
Msg ['to'] =
Part2 = MIMEText (content, 'html', _ charset = 'utf-8 ')
Msg. attach (part2)
Try:
Server = smtplib. SMTP (your email server)
Server. sendmail (me, to, msg. as_string ())
Server. quit ()
Except t Exception, e:
Print e