New IT forum
11 August 2022, 05:34:46 pm *
Welcome, %1$s. Please login or register.

: PiHub now in stock.
 
Pages: [1]

Author Topic: How to send e-mail from the plug  (Read 3903 times)

NewIT_Marcus

  • Hero Member
  • *****
  • Posts: 960
How to send e-mail from the plug
« on: 20 October 2009, 06:15:47 pm »

There are probably many ways of doing this. Here's one way, that worked for me.

  • Install postfix (apt-get install postfix)

Postfix installation will prompt for a setting that is appropriate to your system; in my case I chose "satellite" and specified the name of my ISP mail server (for posting).

Additional postfix configuration:

Create or update file /etc/postfix/sender_canonical:

 root [email protected]_domain.co.uk
 www-data [email protected]_domain.co.uk
 marcus [email protected]_domain.co.uk


Note that in the above examples the named e-mail addresses differ, but in your configuration all three (or more, or fewer) might be identical. The purpose of this file is to map the user names (root, www-data and marcus to the corresponding "real" e-mail addresses. Once we have created this file, we then use it to create a related file named /etc/postfix/sender_canonical.db file that postfix will use:

 postmap /etc/postfix/sender_canonical

Then I edited /etc/postfix/main.cf (one of the configuration files for postfix). 4 lines in particular need to be configured for my setup to work the way I want it: in all cases I have amended the actual values used, but you should be able to identify the lines in question and determine settings appropriate to your own system.

  • myhostname = my_plug_name
  • myorigin = my_sender_domain.co.uk
  • relayhost = my_isp_post_server_name.co.uk
  • #mydestination = my_sender_domain.co.uk, my_plug_name, localhost.localdomain, localhost


Complete contents of /etc/postfix/main.cf:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no
readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = my_plug_name
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
#myorigin = /etc/mailname
myorigin = my_sender_domain.co.uk
#mydestination = my_sender_domain.co.uk, my_plug_name, localhost.localdomain, localhost
relayhost = my_isp_post_server_name.co.uk
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only


After changes to postfix configuration, postfix should be restarted: sudo /etc/init.d/postfix restart

  • Install mailutils (apt-get install mailutils)
  • Install mutt (apt-get install mutt) - for sending e-mail from the command line

With mailutils and mutt, you can send mail from the command line:

echo 'this is a test' > emailbody.txt
mutt -s 'email test' [email protected]_domain.co.uk < emailbody.txt


I only installed mutt for the benefit of easy testing from the command line (or in a script); if you were configuring (for example) a php package to send mail, mutt certainly wouldn't be required. (Possibly mailutils too, I'll look into that).

Postfix can be devilishly complicated, but the above settings work in my environment, for connection to an ISP mail server. You may need to research postfix configuration to fine tune the settings for your environment.
« Last Edit: 20 October 2009, 06:17:19 pm by NewIT_Marcus »
Logged
Pages: [1]
 
 

Powered by MySQL Powered by PHP SMF 2.0.10 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!