Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:services:email:smtp.client [2024/10/14 17:41] – [Installation] bartprokopdocs:guide-user:services:email:smtp.client [2024/12/14 23:05] – move old clients to bottom stokito
Line 19: Line 19:
  
 "smarthost only" means that the program is only capable to send email through a configured "smarthost", that is, it cannot directly deliver to the destination SMTP server. E.g. it won't make a DNS lookup of the email address for MX record. "smarthost only" means that the program is only capable to send email through a configured "smarthost", that is, it cannot directly deliver to the destination SMTP server. E.g. it won't make a DNS lookup of the email address for MX record.
- 
-===== Using mailsend ===== 
- 
-==== Description ==== 
- 
-<code> 
-Mailsend is a simple command line program to send mail via SMTP protocol. 
-</code> 
- 
-Being quite lightweight and not requiring any configuration, mailsend is ideal for sending mails in shell scripts. 
- 
-[[https://github.com/muquit/mailsend]] - Sources and issues 
-==== Installation ==== 
- 
-Depending on whether you want SSL support or not (actually, the size of libopenssl will probably be the decisive factor), install one of the two versions: 
- 
-<code> 
-opkg install mailsend 
-opkg install mailsend-nossl 
-</code> 
- 
-==== Usage ==== 
- 
-Simple usage: 
- 
-<code> 
-mailsend -f root@openwrt -t foo@example.com -smtp smtp.example.com -sub "My subject" -msg-body /tmp/body 
-</code> 
- 
-For advanced usage (MIME attachements, authentication, BCC, etc), see: 
- 
-<code> 
-mailsend -h 
-mailsend -example 
-</code> 
  
 ===== Using msmtp ===== ===== Using msmtp =====
Line 59: Line 24:
 ==== Description ==== ==== Description ====
  
-<code> +msmtp is an SMTP client. 
-msmtp is an SMTP client. In the default mode, it transmits a mail to +In the default mode, it transmits a mail to an SMTP server (for example at a free mail provider) which does the delivery. 
-an SMTP server (for example at a free mail provider) which does the +To use this program with your mail user agent (MUA), create a configuration file with your mail account(s) and tell your MUA to
-delivery. To use this program with your mail user agent (MUA), create +
-a configuration file with your mail account(s) and tell your MUA to+
 call msmtp instead of /usr/sbin/sendmail. call msmtp instead of /usr/sbin/sendmail.
-</code> 
  
 Since msmtp understands standard sendmail options, it can be used in places where sendmail is expected (e.g. PHP code). Since msmtp understands standard sendmail options, it can be used in places where sendmail is expected (e.g. PHP code).
Line 72: Line 34:
  
 ==== Installation ==== ==== Installation ====
-<code>opkg install msmtp-mta</code> +<code> 
-Installing ''%%msmtp-mta%%'' package will also create necessary ''%%sendmail` symlinks%%'' If you do not need ''%%sendmail%%'' command (unlikely) then install only ''%%msmtp%%'' package.+opkg install msmtp-mta 
 +</code> 
 + 
 +Installing ''msmtp-mta'' package will also create necessary ''sendmail'' symlink. If you do not need ''sendmail'' command (unlikely) then install only ''msmtp'' package. 
 ==== Configuration ==== ==== Configuration ====
-Place your configuration in ''%%/etc/msmtprc%%''There is an existing ''%%default%%''-block in the included config file so if you want to call ''%%msmtp%%'' without specifying an account, then you need to rename the existing ''%%default%%''-block to something else.+For router configuration, you very likely do not want to receive emails to local mailboxes. Define aliases file ''/etc/aliases.msmtp'' to send all local mails to your admin email:
  
-Here is an example configuration using Gmail that worlks with 2FA and an app password:+<code - /etc/aliases.msmtp> 
 +defaultadmin@example.com 
 +</code>
  
-<code> +Place your configuration in ''/etc/msmtprc''. There is an existing ''default'' block in the included config file so if you want to call ''msmtp'' without specifying an account, then you need to rename the existing ''default'' block to something else.
-# Example for a system wide configuration file+
  
-# A system wide configuration file is optional+Here is an example configuration using Gmail that works with 2FA and an app password: 
-If it exists, it usually defines a default account.+ 
 +<code bash /etc/msmtprc> 
 +# A system wide configuration file. 
 +It defines a default account.
 # This allows msmtp to be used like /usr/sbin/sendmail. # This allows msmtp to be used like /usr/sbin/sendmail.
-# cat /etc/msmtprc 
  
 +# Set default values.
 defaults defaults
-account default+aliases /etc/aliases.msmtp 
 +syslog LOG_MAIL
  
 +# Gmail configuration that works with 2FA and an app password.
 +# Use TLS on port 465. On this port, TLS starts without STARTTLS.
 +account gmail
 host smtp.gmail.com host smtp.gmail.com
 port 465 port 465
Line 95: Line 69:
 tls on tls on
 tls_starttls off tls_starttls off
 +from_full_name Apartment Router
 +from home.lab@gmail.com
 +user home.lab@gmail.com
 +password abcd efgh ijkl mnop
  
-from abc@gmail.com +# Select the default account 
-user abc@gmail.com +account default : gmail
-password app_passwd_here +
- +
-syslog LOG_MAIL+
 </code> </code>
  
-Now symlink ''%%msmtp%%'' to ''%%sendmail%%'' with ''%%ln -s /usr/bin/msmtp /usr/sbin/sendmail%%''. +Now symlink ''msmtp'' to ''sendmail'' with ''ln -s /usr/bin/msmtp /usr/sbin/sendmail'' - this is not necessary if ''msmtp-mta'' was installed instead of ''msmtp''.
  
 Also you may configure env variables ''EMAIL'' for From address and ''SMTPSERVER'' to specify smarthost. Also you may configure env variables ''EMAIL'' for From address and ''SMTPSERVER'' to specify smarthost.
  
 ==== Sending mail ==== ==== Sending mail ====
-<code>+ 
 +<code bash> 
 +echo -e "Subject: Test mail\n\nThis is a test \"message\"." | sendmail abcd
 echo -e "Subject: Test mail\n\nThis is a test \"message\"." | sendmail -f "<something@your-domain.tld>" "<recipient@destination.tld>" echo -e "Subject: Test mail\n\nThis is a test \"message\"." | sendmail -f "<something@your-domain.tld>" "<recipient@destination.tld>"
 </code> </code>
  
-Note that //sendmail// (''%%/usr/sbin/sendmail%%'') is a symlink to ''%%/usr/bin/msmtp%%''. +Note that the //sendmail// command (''/usr/sbin/sendmail'') is a symlink to ''/usr/bin/msmtp''.
- +
- +
-===== Using mini-sendmail ===== +
- +
-==== Description ==== +
- +
-^ Name ^ Version ^ Dependencies ^ Size ^ Description +
-| mini-sendmail  |  1.3.6-4  |  //none//  |   5866 | mini_sendmail reads its standard input up to an end-of-file and sends a copy of the message found there to all of the addresses listed. The message is sent by connecting to a local SMTP server. This means ''mini_sendmail'' can be used to send email from inside a chroot(2) area.  | +
- +
-[[https://acme.com/software/mini_sendmail/|Official site]] +
-==== Installation and Configuration ==== +
- +
-<code>opkg install mini-sendmail</code> +
- +
-On Chaos Calmer, the package is no longer available, but the version from Barrier Breaker still works (AA & BB versions as installed below work in AA):+
  
 +Use ''logread'' to check for the following log entry:
 <code> <code>
-opkg install http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages/mini-sendmail_1.3.6-4_ar71xx.ipk+Mon Oct 14 23:35:55 2024 mail.info msmtp: host=smtp.gmail.com tls=on auth=on user=******@gmail.com from=******@gmail.com recipients=admin@example.com mailsize=181 smtpstatus=250 smtpmsg='250 2.0.0 OK  1728948955 b640f23e62c3d-c9d29717ba4su6358366z.33 - gsmtp' exitcode=EX_OK
 </code> </code>
  
-==== Example ==== 
-<code bash> 
-mini_sendmail -ssmtp.mail.yahoo.com -p465 -t foo@example.com < input_file 
  
-usage: mini_sendmail [-f<name>] [-t] [-s<server>] [-p<port>] [-T<timeout>] [-v] [address ...] +===== Using ssmtp =====
-</code>+
  
-Note that there must not be a space between the option and the value; e.g. "-p 465" is incorrect.+==== Description ====
  
-Several sample configurations found on the internet failedbut as of 160413, this worked +A secureeffective and simple way of getting mail off a system to your mail hub. 
-<code bash>  +It contains no suid-binaries or other dangerous things no mail spool to poke around in, and no daemons running in the background
-echo -e 'From: valid@email.com\r\nSubject: Test Subject\r\n\r\nTesting\r\n.' | mini_sendmail -fvalid@email.com -smail.brighthouse.com toAddr@gmail.com +mail is simply forwarded to the configured mailhost. Extremely easy configuration.
-</code> +
-smtp.gmail.com failed; omitting -f failed; omitting "From: " resulted in transmissionbut no sender shown+
- +
-This is a very small package if you can find an smtp server which works and you can configure the command so that the server accepts it. +
- +
-===== Using ssmtp =====+
  
 [[https://tracker.debian.org/pkg/ssmtp|Official site]] [[https://tracker.debian.org/pkg/ssmtp|Official site]]
  
-==== Description ====+==== Installation ====
  
 <code> <code>
-A secure, effective and simple way of getting mail off a system to your +opkg install ssmtp
-mail hub. It contains no suid-binaries or other dangerous things - no +
-mail spool to poke around in, and no daemons running in the background. +
-mail is simply forwarded to the configured mailhost. Extremely easy +
-configuration.+
 </code> </code>
- 
-==== Installation ==== 
- 
-<code>opkg install ssmtp</code> 
  
 ==== Usage ==== ==== Usage ====
Line 173: Line 117:
 ssmtp expects its two configuration files named ''/etc/ssmtp/revaliases'' and ''/etc/ssmtp/ssmtp.conf''. Both are self-explaining: ssmtp expects its two configuration files named ''/etc/ssmtp/revaliases'' and ''/etc/ssmtp/ssmtp.conf''. Both are self-explaining:
  
-<code+<code bash /etc/ssmtp/ssmtp.conf>
-/etc/ssmtp/ssmtp.conf+
 root=arnold@gmx.net root=arnold@gmx.net
 mailhub=mail.gmx.net:465 mailhub=mail.gmx.net:465
Line 184: Line 127:
 </code> </code>
  
-<code+<code bash /etc/ssmtp/revaliases>
-/etc/ssmtp/revaliases+
 # Format: local_account:outgoing_address:mailhub # Format: local_account:outgoing_address:mailhub
 root:arnold@gmx.net:mail.gmx.net:465 root:arnold@gmx.net:mail.gmx.net:465
-</code+</code>
  
 To use the program, with SMTP auth: To use the program, with SMTP auth:
Line 216: Line 158:
  
 You may also need ''SMTP_ANTISPAM_DELAY'' env to bypass the Greylisting antispam if it enabled for submission. You may also need ''SMTP_ANTISPAM_DELAY'' env to bypass the Greylisting antispam if it enabled for submission.
 +
 +
 +===== Using mailsend =====
 +
 +==== Description ====
 +
 +Mailsend is a simple command line program to send mail via SMTP protocol.
 +
 +Being quite lightweight and not requiring any configuration, ''mailsend'' is ideal for sending mails in shell scripts.
 +
 +[[https://github.com/muquit/mailsend]] - Sources and issues
 +
 +==== Installation ====
 +
 +Depending on whether you want SSL support or not (actually, the size of libopenssl will probably be the decisive factor), install one of the two versions:
 +
 +<code>
 +opkg install mailsend
 +opkg install mailsend-nossl
 +</code>
 +
 +==== Usage ====
 +
 +Simple usage:
 +
 +<code bash>
 +mailsend -f root@openwrt -t foo@example.com -smtp smtp.example.com -sub "My subject" -msg-body /tmp/body
 +</code>
 +
 +For advanced usage (MIME attachments, authentication, BCC, etc), see:
 +
 +<code>
 +mailsend -h
 +mailsend -example
 +</code>
 +
 +
 +
 +===== Using mini-sendmail =====
 +
 +==== Description ====
 +
 +mini_sendmail reads its standard input up to an end-of-file and sends a copy of the message found there to all of the addresses listed.
 +The message is sent by connecting to a local SMTP server. This means ''mini_sendmail'' can be used to send email from inside a chroot(2) area.
 +
 +[[https://acme.com/software/mini_sendmail/|Official site]]
 +
 +==== Installation and Configuration ====
 +
 +<code>
 +opkg install mini-sendmail
 +</code>
 +
 +On Chaos Calmer, the package is no longer available, but the version from Barrier Breaker still works (AA & BB versions as installed below work in AA):
 +
 +<code>
 +opkg install http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages/mini-sendmail_1.3.6-4_ar71xx.ipk
 +</code>
 +
 +==== Example ====
 +
 +<code bash>
 +mini_sendmail -ssmtp.mail.yahoo.com -p465 -t foo@example.com < input_file
 +
 +usage: mini_sendmail [-f<name>] [-t] [-s<server>] [-p<port>] [-T<timeout>] [-v] [address ...]
 +</code>
 +
 +Note that there must not be a space between the option and the value; e.g. "-p 465" is incorrect.
 +
 +Several sample configurations found on the internet failed, but as of 160413, this worked
 +<code bash> 
 +echo -e 'From: valid@email.com\r\nSubject: Test Subject\r\n\r\nTesting\r\n.' | mini_sendmail -fvalid@email.com -smail.brighthouse.com toAddr@gmail.com
 +</code>
 +smtp.gmail.com failed; omitting -f failed; omitting "From: " resulted in transmission, but no sender shown.
 +
 +This is a very small package if you can find an smtp server which works and you can configure the command so that the server accepts it.
 +
  
  
  • Last modified: 2024/12/14 23:20
  • by stokito