< Tags de E-mail
home / infca / email (navigation links)
Més lluny, hem d'anar més lluny, dels arbres caiguts que ara ens empresonen

MIME | list Subject | Tinet | BLAT | SendEmail | Telnet | send tomatic | to & from
mutt : use it, configuracio, send minim (amb 2 Attachments), debug
*** backup fitxers importants *** | free services, errors | gmail SMTP server access -> send from Minie to Proton
LDAP (ext) | Pend | Links | End | mapa

e-mail : tags, ids, servers, protocols, ...

go 2 top
Email standards

lemis

JavaWorld

send / receive
.--------------------------------------------. | server | | | | 25 110 pop3 143 imap | | 465 587 995 pop3s 993 imaps | .--------------------------------------------. ^ ^ | | | | V V [smtp] [ssmtp] [pop3] [imap] ^ ^ | | | | V V .--------------------------------------------. | client | .--------------------------------------------.
SMTP

Es fa servir per enviar missatges al servidor SMTP

port 465 versus 587

Resum de diferències

Característica Port 587 Port 465 Xifratge STARTTLS (TLS explícit) SSL/TLS implícit (des de l'inici) Inici Connexió Text pla, després s'actualitza a TLS Directament xifrat amb TLS Estat Actual Estàndard i recomanat Històricament usat; alguns el consideren "obsolet", altres "rehabilitat" (confús)
POP3

RFC 1939 - Post Office Protocol Version 3

POP3 is just a protocol to get an SMTP buffer from a server, and SMTP does not deal with folders.

IMAP4

Internet Message Access Protocol (IMAP) is an Internet standard protocol used by e-mail clients to retrieve e-mail messages from a mail server over a TCP/IP connection.

IMAP was designed with the goal of permitting complete management of an email box by multiple email clients. Therefore clients generally leave messages on the server until the user explicitly deletes them.

An IMAP server typically listens on port number 143. IMAP over SSL (IMAPS) is assigned the port number 993.

RFC 3501 - Internet Message Access Protocol - version 4rev1


Components


                        (MTA)              (MDA)
 [user] =======> [MUA] =======> [MTA] =======> [ relay ] =======> [MTA] =======> [MUA] =======> [user]
         (SMTP)                                                                         (POP)


Email blocks

iapplianceweb

Email blocks

scit.wlv.ac.uk

install SMTP


2.3.1 Mail Objects [rfc2821]

SMTP transports a mail object. A mail object contains an envelope and content.
The SMTP envelope is sent as a series of SMTP protocol units. It consists of an originator address (to which error reports should be directed); one or more recipient addresses; and optional protocol extension material.
The SMTP content is sent in the SMTP DATA protocol unit and has two parts: the headers and the body. If the content conforms to other contemporary standards, the headers form a collection of field/value pairs structured as in the message format specification; the body, if structured, is defined according to MIME.

4.1 SMTP commands Semantics and Syntax

The SMTP commands define the mail transfer or the mail system function requested by the user. SMTP commands are character strings terminated by <CRLF>. The commands themselves are alphabetic characters terminated by <SP> if parameters follow and <CRLF> otherwise.

SMTP commands
4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO)
Indicate client's identity
4.1.1.2 MAIL (MAIL)
This command is used to initiate a mail transaction in which the mail data is delivered to an SMTP server which may, in turn, deliver it to one or more mailboxes or pass it on to another system.
4.1.1.3 RECIPIENT (RCPT)
This command is used to identify an individual recipient of the mail data; multiple recipients are specified by multiple use of this command.
4.1.1.4 DATA (DATA)
This command causes the mail data to be appended to the mail data buffer. The mail data is terminated by a line containing only a period, that is, the character sequence "<CRLF>.<CRLF>"
4.1.1.5 RESET (RSET)
This command specifies that the current mail transaction will be aborted. Any stored sender, recipients, and mail data MUST be discarded, and all buffers and state tables cleared. The receiver MUST send a "250 OK" reply to a RSET command with no arguments. A reset command may be issued by the client at any time.
4.1.1.6 VERIFY (VRFY)
This command asks the receiver to confirm that the argument identifies a user or mailbox.
4.1.1.7 EXPAND (EXPN)
This command asks the receiver to confirm that the argument identifies a mailing list, and if so, to return the membership of that list.
4.1.1.8 HELP (HELP)
Syntax:
"HELP" [ SP String ] CRLF
4.1.1.9 NOOP (NOOP)
This command does not affect any parameters or previously entered commands. It specifies no action other than that the receiver send an OK reply.
4.1.1.10 QUIT (QUIT)
This command specifies that the receiver MUST send an OK reply, and then close the transmission channel
Amunt! Top Amunt!
3.3 Mail Transactions

There are three steps to SMTP mail transactions. The transaction starts with a MAIL command which gives the sender identification. (In general, the MAIL command may be sent only when no mail transaction is in progress; see section 4.1.4.) A series of one or more RCPT commands follows giving the receiver information. Then a DATA command initiates transfer of the mail data and is terminated by the "end of mail" data indicator, which also confirms the transaction.

(1) The first step in the procedure is the MAIL command.

MAIL FROM:<reverse-path> [SP <mail-parameters> ] <CRLF>

If accepted, the SMTP server returns a 250 OK reply. Normally, failures produce 550 or 553 replies.

(2) The second step in the procedure is the RCPT command.

RCPT TO:<forward-path> [ SP <rcpt-parameters> ] <CRLF>

If accepted, the SMTP server returns a 250 OK reply and stores the forward-path. If the recipient is known not to be a deliverable address, the SMTP server returns a 550 reply.

(3) The third step in the procedure is the DATA command (or some alternative specified in a service extension).

DATA <CRLF>

SMTP indicates the end of the mail data by sending a line containing only a "." (period or full stop).

If accepted, the SMTP server returns a 250 OK reply.


When RFC 822 format is being used, the mail data include the memo header items such as Date, Subject, To, Cc, From.


Amunt! Top Amunt!
MIME

RFC 822 describes a generic message format, and specifies some standard header information. It says almost nothing about the body of the messages, except that it is a chunk of ASCII text.
MIME takes advantage of that by superimposing a format for the body text, and it also defines some header lines of its own. The neat thing is that since the body is still just a chunk of text, it doesn't break any rules established by RFC 822. This means that any RFC 822-compliant transport system can handle MIME messages without modification.

Of course, the receiving clients of the message do care because that chunk of text has to be converted back into a binary file. They can do this only if they know about the format of the message, i.e., only if they are MIME-compliant mail readers.

CodeGuru

MIME links

MIME encodes a file into the following 64 alphanumeric characters:

ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789+/

Tag Params Desc Misc
       

Sample (displayed by Yahoo!) :

           X-Apparently-To: sebastiasebas@yahoo.com via 216.136.173.245; 29 Apr 2003 07:50:44 -0700 (PDT)
               Return-Path: <xjeanj3470p7@msn.com>
                  Received: from 64.108.85.177 (64.108.85.177)
                                 by mta499.mail.yahoo.com with SMTP;
                                 29 Apr 2003 07:50:39 -0700 (PDT)
               Return-Path: kmichael1WwR6N7xgk6fVB@msn.com
                      From:
                   Subject: Men Say Yes: Large Breasts Are the Best
                  Reply-to: kmichael1WwR6N7xgk6fVB@msn.com
                        To: "Kissik Ang" <Cheely@netscape.net>
                      Date: Tue, 29 Apr 2003 10:50:27 -0400
                Importance: Normal
                X-Priority: 3 (Normal)
                  X-Sender: "Spurlock Oz" <SpurlockOz@canoemail.com>
          X-Originating-Ip: [0.8.1.35]
                  X-Mailer: MSN Explorer 7.00.0021.1900
              MIME-Version: 1.0
              Content-Type: multipart/alternative; boundary="7grj1uPO3j2nQYc4 ... QB808i7yvWLv"
 Content-Transfer-Encoding: 7bit
            Content-Length: 1460

Mitjançant Opera i "Display all headers" podem veure :

Para:                          Sebas <altemir@es.abc.com>
Asunto:                        prova
De:                            Salvador Pixatintes <salvadorP@yahoo.com>
Organizaci¢n:                  Ajuntament
Content-Type:                  text/plain; format=flowed; charset=iso-8859-15
MIME-Version:                  1.0
Content-Transfer-Encoding:     8bit
Fecha:                         Tue, 18 Nov 2003 23:24:03 +0100
Message-ID:                    <opryutudd64ta7ll@smtp.tinet.org>
User-Agent:                    Opera7.22/Win32 M2 build 3221


Albert's PYTHON (fake)

#!/usr/bin/python
#
# send mail: to whoever, from whoever you think of, and from wherever you want to be :-)
#

import sys
# import socket
import smtplib

if __name__ == '__main__':                      # run this code only if NOT imported

    print( sys.argv )
    if len(sys.argv) != 5:
        print( "format is <from> <to> <subject> <body>\n" )
        sys.exit (-1)
    else:
        smtpconn = smtplib.SMTP ('localhost')
        print( "Sending mail from:", sys.argv[1] )
        print( "Sending mail to:", sys.argv[2] )
        print( "Subject:", sys.argv[3] )
        print( "Body:", sys.argv[4] )

        print( "in progress..." )
        smtpconn.sendmail (sys.argv[1], sys.argv[2], "Subject: " + sys.argv[3] + "\r\n" + sys.argv[4])
        print( "done" )
        sys.exit (0)

Requires (as Golemz) a Debian + exim (SMTP server)

A message sent to Gmail comes up as (Open + More Options + Show Original) :

 X-Gmail-Received: 725288c5991ed284d30fd3ef126d7e9433597cf8
 Delivered-To:     sebastiasebas@gmail.com
 Received:         by 10.38.125.77 with SMTP id x77cs11720rnc;
                        Wed, 27 Oct 2004 08:04:14 -0700 (PDT)
 Received:         by 10.38.152.73 with SMTP id z73mr855689rnd;
                        Wed, 27 Oct 2004 08:04:13 -0700 (PDT)
 Return-Path:      <fromme.casameva@quisapon.net>
 Received:         from karisma ([62.57.139.245])
                        by mx.gmail.com with ESMTP id 63si3302rna;
                        Wed, 27 Oct 2004 08:04:13 -0700 (PDT)
Received-SPF:      neutral (gmail.com: 62.57.139.245 is neither permitted nor denied by
                        domain of fromme.casameva@quisapon.net)
Received:          from karisma ([127.0.0.1])
                        by karisma with esmtp (Exim 3.35 #1 (Debian))
                        id 1CMpJJ-00038a-00
                        for <sebastiasebas@gmail.com>; Wed, 27 Oct 2004 17:02:01 +0200
Subject:           Tema del dia
Message-Id:        <E1CMpJJ-00038a-00@karisma>

From: fromme.casameva@quisapon.net
Bcc:
Date: Wed, 27 Oct 2004 17:02:01 +0200

Hola xaval - ke me'n dius ?

A similar message sent to Yahoo comes up as (Full Headers) :

 X-Apparently-To : sebastiasebas@yahoo.com via 206.190.39.206; Wed, 03 Nov 2004 09:15:08 -0800
 X-YahooFilteredBulk : 62.57.139.245
 X-Originating-IP : [62.57.139.245]
 Return-Path : <kagalda.o.no@kagalda.brut>
 Received : from 62.57.139.245 (EHLO karisma) (62.57.139.245) by mta108.mail.re2.yahoo.com
     with SMTP; Wed, 03 Nov 2004 09:15:08 - 0800
 Received : from karisma ([127.0.0.1]) by karisma with esmtp (Exim 3.35 #1 (Debian)) id 1CPOhN-0005Ms-00 for
     <sebastiasebas@yahoo.com>; Wed, 03 Nov 2004 18:13:29 +0100
 Subject : Tema del dia
 Message-Id : <E1CPOhN-0005Ms-00@karisma>
 From : kagalda.o.no@kagalda.brut
 Bcc :
 Date : Wed, 03 Nov 2004 18:13:29 +0100
 Content-Length : 28

Hola xaval - ke me'n dius ?

Sending mail
from perl
#!/usr/bin/perl $to = 'abcd@gmail.com'; $from = 'webmaster@yourdomain.com'; $subject = 'Test Email'; $message = 'This is test email sent by Perl Script'; open(MAIL, "|/usr/sbin/sendmail -t"); # Email Header print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; # Email Body print MAIL $message; close(MAIL); print "Email Sent Successfully\n";

url

1.- from bash, a one-liner using mail command

The more simple is :

echo "Testing...1...2...3" | ssmtp -v myusername@gmail.com

Using a file :

cat my_message.txt | ssmtp myusername@gmail.com Where my_message can be formatted to have lines for TO: and SUBJECT: and the body. TO: abc@def.com SUBJECT: Testing -blank line- Message body goes here....
2.- from bash using mail command

As "/home/sag/eines/backup_per_email/snd_email.sh" :

#!/bin/bash echo "Trace filesystem status into a file" myLog=/home/pi/logs/df.log echo "Generated by /home/pi/sendemail/snd_1.sh" > $myLog df -h >> $myLog echo "Get external IP" ipvariable=$(curl -m 2 -s icanhazip.com); ipvariable=$(curl -m 2 -s http://checkip.amazonaws.com); rc1=$? echo ">>> (2) icanhazip rc ($rc1)" >> $myLog echo "Send an email with a file attached" echo "Today my external IP is {$ipvariable}." echo "Today my external IP is {$ipvariable}." | mail --attach=$myfn -s "From RaspPi service provider" nom1@gmail.com, nom2@gmail.com # sometimes attachment is provided via "-a $myfn" echo "Si hi ha problemes, revisa /var/log/mail.log i /var/log/mail.err" echo '.'

Configuration is in /etc/ssmtp/ssmtp.conf

from bash using mutt

Using mutt is far better from the configuration point of view : ~/.muttrc (privat) i /etc/Muttrc (global)

See /usr/share/doc/mutt/README.Debian for details.

# echo "my body" | mutt -s "my subject" -i body.txt -a attachment.txt recipient@example.com -s used to specify subject of mail. -i used to specify file containing message body. -a used to specify attachment file, must be placed at the end of command line options when attaching sigle or multiple files, separating filenames and recipient addresses with "--" is mandatory (man mutt)

geek

A nice one-liner :

sebas@pi0alby:~ $ echo "my BODY" | mutt -s "my SUBJECT" -- destinations@gmail.com

A one-liner with an attachment :

sebas@pi0alby:~ $ echo "my Backup is attached" | mutt -s "my Todays backup" -a my_file.tgz -- destinations@gmail.com GPGME: CMS protocol not available SMTP session failed: 552 5.3.4 Error: message file too big {file was 66 MB} Could not send the message.

We always want to do it from bash :

sebas@minie:~/eines/bash$ cat 1_email_mutt.sh #!/bin/bash my_version="v 1.e" myT=$(date +%R) # short time myD=$(date +"%d/%m/%Y") # short date, 4 digit year, day before month szHora="$myT,$myD" my_body="*** ($szHora) - ($HOSTNAME) - cos del missatge + "${my_version} my_subject="### ($szHora) Minie sends Email "${my_version} echo "${my_body}" | mutt -d 5 -s "${my_subject}" -- "${my_destination}" # debug at max level cat ~/.muttdebug0 # display last session trace exit 0
20221106 - an error at R3, or how to debug a mutt problem

sag@odin:~ $ echo "my BODY" | mutt -s "my SUBJECT" -- seb@gmail.com GPGME: CMS protocol not available SASL authentication failed Could not send the message. sag@odin:~ $ echo "my BODY" | mutt -d 5 -s "my SUBJECT" -- seb@gmail.com sag@odin:~ $ cat ~/.muttdebug0 [2022-11-06 14:22:39] External authentication name: adb30 [2022-11-06 14:22:39] mutt_sasl_cb_authname: getting authname for smtp.tinet.cat:465 [2022-11-06 14:22:39] mutt_sasl_cb_authname: getting user for smtp.tinet.cat:465 [2022-11-06 14:22:39] mutt_sasl_cb_pass: getting password for adb30@smtp.tinet.cat:465 [2022-11-06 14:22:39] 4> AUTH PLAIN YWRiMzAAYWRiMzAAYWRiMzAyMDAz [2022-11-06 14:22:41] 4< 535 5.7.8 Error: authentication failed:

Solution : fix password in /etc/Muttrc, field smtp_pass

send an email to a local user

$ echo "Test message" | mutt -s "Test subject" localuser
from bash using msmtp

See Pi0 !

origins and destinations

Some machines send automatic emails, as backup or external IP info. El resum és :

Host Email Dades Com Desti Checked ? ----- ------ ------ ---- ----- ---------- odin adb30 ip /etc/cron.hourly bisc2k9/adb30 ✔ ADB@odin pere@yandex.com/odin ✔ backup crontab 05:33 sag manel@yandex ✔ /home/sebas/dades/python/email/read_imap_mail/yndx_mc_odin.sh neus@gmx --- sveta@aol.com/odin ✔ /home/sebas/dades/python/email/read_imap_mail/aol.sh 2 pi0 cdet ip /etc/cron.hourly bisc2k9/pi0 ✔ QPatPi0 pere@yandex.com/pi0 ✔ backup crontab 05:30 manel@yandex ✔ /home/sebas/dades/python/email/read_imap_mail/yndx_mc_pi0.sh neus@gmx --- {removed 20240502} sveta@aol.com/r0 ✔ /home/sebas/dades/python/email/read_imap_mail/aol.sh 3 r4 japlan ip /etc/cron.hourly bisc2k9/r4 ✔ APC al R4 pere@yandex.com/r4 ✔ backup crontab 05:40 manel@yandex ✔ /home/sebas/dades/python/email/read_imap_mail/yndx_mc_r4.sh neus@gmx --- {removed 20250429} sveta@aol.com/r4 ✔ /home/sebas/dades/python/email/read_imap_mail/aol.sh 4 mars/minie bcn.borinot@g ip /etc/cron.hourly bisk2k9/mars_ip ✔ Mutt at Minie pere@yandex/mars ✔ backup crontab 11:57 manel@yandex ✔ /home/sebas/dades/python/email/read_imap_mail/yndx_mc_mars.sh neus@gmx --- {removed 20231221} sveta@aol.com/mars ✔ /home/sebas/dades/python/email/read_imap_mail/aol.sh 5 t60 prun.era JF . raspall . ChP . henry . ET .

The details of the operations are :

hostname start period shell command cfg id {a} log destination attch verify bash @ mars/minie --------- ------ ------- ------ -------- ---- ------- ---- ------------ ------ --------- ------------ odin /etc/cron.hourly 1 hour /home/pi/sendemail/snd_1.sh mail /etc/Muttrc adb30 send_emilio.log llovetbasura,bisc2k9,pere@yandex + ip 20200605 yndx_pere_odin.sh (-) b2k_odin manual - /home/sag/eines/backup_per_email mail /etc/ssmtp . fer_backup_email.log johan@yandex + . . crontab 05:33 1 day /home/pi/eines/fer_backup.sh tar+mutt /etc/Muttrc adb30 fer_backup.log manel@yandex + sveta@aol + (3) 20200605 yndx_mc_odin.sh pi0 /etc/cron.hourly 1 hour /home/pi/eines/envia_ip.sh mutt /etc/Muttrc cdet/QP@pi0 envia_ip.log bisk2k9 + pere@yandex . 20200801 yndx_pere_pi0.sh crontab 05:30 1 day /home/pi/eines/backup/fer_backup.sh tar+mutt /etc/Muttrc cdet/QP@pi0 fer_backup.log manel@yandex + sveta@aol + (3) ip 20200720 yndx_mc_pi0.sh + gmx_neus.sh r4 /etc/cron.hourly 1 hour /home/pi/eines/3_envia_ip.sh mutt . . . bisc2k9@g, pere@yandex.com . crontab 05:40 1 day /home/sebas/eines/backup/fer_backup.sh tar+mutt /etc/Muttrc japlan fer_backup.log manel@yandex + sveta@aol + (3) ip 20210312 yndx_mc_pi4.sh + gmx_neus.sh mars/minie /etc/cron.hourly 1 hour /home/nicolau/eines/envia_ip.sh mutt /etc/Muttrc z.berto/JGT@mars envia_ip.log bisk2k9 + pere@yandex . 20200615 yndx_pere_mars.sh (-) b2k_mars crontab 11:57 1 day /home/nicolau/eines/fer_backup.sh tar+mutt /etc/Muttrc z.berto/JGT@mars fer_backup.log manel@yandex + sveta@aol + (3) 20200605 yndx_mc_mars.sh t60 /etc/cron.weekly 1 week /home/sebas/eines/backup/fer_backup.sh tar+mutt /etc/Muttrc prun.era/JF@T60 fer_backup.log ( z.berto + pere@yandex ) + (3) 20200605 yndx_pere_t60.sh raspall crontab 1 day /home/pi/sendemail/snd_1.sh mail /etc/ssmtp charito.posada@g cron_job.log llovetbasura + bisc2k9 - . 20200605 (-) b2k_raspall henry /etc/cron.hourly 1 hour /home/enric/sh-enric/ip.sh mail /etc/ssmtp joseph.turreta@g ip.log genrybasura,bisc2k9,pere@yandex + - 20200605 b2k_esp.sh /etc/cron.daily 1 day /sebas/eines/backup_by_mail/fer_backup.sh mail / . . enricsarra@yandex + neus@gmx + . . . pomnia /etc/cron.hourly 1 hour /home/mate/envia-email/envia_ip.sh mutt /etc/Muttrc z.berto envia_email.log bisc2k9 - . . . /etc/cron.weekly 1 week /home/mate/backup_omnia/fer_backup.sh mutt /etc/Muttrc z.berto fer_backup.log prun.era + (1) . . grafic . . . . . . . . . . . .

{a} sender's id is set in /etc/Muttrc

Backups are sent to manel@yandex (+) & sveta@aol (+) : mars/minie, pi0, odin, henry, r4
IPs are sent to pere@yandex (?) & bisc2k9@g (+) & z.berto (-) : mars, pi0, odin, henry

Soft links created by

sebas@pi0alby:/etc/cron.hourly $ sudo ln -s /home/sebas/eines/envia_ip.sh envia_ip_per_email sebas@pi0alby:/etc/cron.daily $ sudo ln -s /home/sebas/eines/backup/fer_backup.sh envia_tgz_per_email

But then the "root" user does not know where to place the tgz file ! So we do (at PiZero) :

15 1 * * * cd /home/sebas/eines/backup/ && /home/sebas/eines/backup/fer_backup.sh 33 * * * * cd /home/sebas/python/tinet/ && /home/sebas/python/tinet/enviar_ip_a_tinet.py >> /home/sebas/logs/enviar_ip_a_tinet.log 2>&1;

(1) 7z.ki = 3x Alpha (uc) || 3x Omega (lc)

(2) foto_t60.txt file generated by /home/sebas/eines/backup/fer_backup.sh
See guifi or rspi or t60

(3) use tar keeping directories ! last shell

(4) no email but via HTML

force cron commands

run-parts --test /etc/cron.hourly/ - verify all is OK, as "she-bang" sudo run-parts -v /etc/cron.hourly/ - run all scripts in the directory, verbose
nice imap python tools at Minie

As to verify email reached destination :

/home/nicolau/sebas/python/email/read_imap_mail/

Need to have an "APP pwd" at Yandex and AOL !

send to yandex and verify

(1) send

sebas@minie:~/eines/bash$ ./1_email_mutt.sh sebas@minie:~/eines/bash$ ./3_envia_ip.sh

(2) verify

sebas@minie:~/dades/python/email/IMAP_read_mail$ ./yndx_pere_mars.sh ++++++++++++++++++++ Got (5) params. ++++++++++++++++++++++++++++++++++++++++ User (pere.pocapor). ++++++++++++++++++++++++++++++++++++++++ Pwd (iddujkfoaaycmgai). ++++++++++++++++++++++++++++++++++++++++ Box (mars). ++++++++++++++++++++++++++++++++++++++++ Server (imap.yandex.com). (1) *** connect to server ( imap.yandex.com ). (2) *** login to user ( pere.pocapor ). (3) *** list of available folders or gmail labels (4) *** connect to specific folder ( mars ). (5) tenim 3 msg (6) select ( 1 2 3 ) msg (7) IDS ( b'1 2 3' ). (8) ID LIST ( [b'1', b'2', b'3'] ). (9) Msg ID is ( b'1' 3 ). (10) subject { MARS, 18:07,24/07/2025 } (9) Msg ID is ( b'2' 3 ). (10) subject { ### tema del missatge + v 1.d } (9) Msg ID is ( b'3' 3 ). (10) subject { ### tema del missatge + v 1.d } (11) close (12) logout user {pere.pocapor} - shutdown connection to server {imap.yandex.com}.
display destination folders

sebas@minie:~/dades/python/email/read_imap_mail$ ./aol.sh 2 { display Odin } sebas@minie:~/dades/python/email/read_imap_mail$ ./aol.sh 3 { display PiZero } -- NULL ??? cdet @ tine *** ok sebas@minie:~/dades/python/email/read_imap_mail$ ./aol.sh 4 { display R4 } -- NULL ??? japlan @ tine *** ok sebas@minie:~/dades/python/email/read_imap_mail$ ./aol.sh 5 { display Minie }
clear a remote folder

sebas@minie:~/dades/python/email/read_imap_mail/esborrar$ ls -al 1_yndx_pere_mars.sh 2_yndx_pere_odin.sh 3_yndx_pere_pi0.sh 4_yndx_pere_r4.sh 5_yndx_manel_mars.sh 6_yndx_manel_odin.sh 7_yndx_manel_pizero.sh 8_yndx_manel_r4.sh delete_files_in_folder.py ./aol/5_aol_sveta_mars.sh ./aol/6_aol_sveta_odin.sh ./aol/7_aol_sveta_r0.sh ./aol/8_aol_sveta_r4.sh

stack overflow - how to delete messages

mailbox size limit exceeded

pere@yandex, 2023-06-15

ESP backup

Envia

cant send TGZ via gmail

If /etc/ssmtp/ssmtp.conf contains "mailhub=smtp.gmail.com:587", we get an error when sending a TGZ file in an email

May 5 15:18:54 odin sSMTP[3376]: 552 5.7.0 message content and attachment content guidelines. k17sm3687326wmi.10 - gsmtp
Use mutt (and nothing else)

Mutt is a text-based mail client. It focuses primarily on being a Mail User Agent (MUA).

Homepage debug tips

install mutt

Install mutt with this sequence :

  1. sudo apt-get install mutt
  2. mkdir -p ~/.mutt/cache/headers
  3. mkdir ~/.mutt/cache/bodies
  4. touch ~/.mutt/certificates
configure mutt

You can set

We shall use the "global" configuration, for all users of the machine

$ cat /etc/Muttrc set from = "my_tinet_user@t1net.cat" set realname = "My Name to be seen" set imap_user = "my_tinet_user@t1net.cat" set imap_pass = "my_tinet_pwd" set smtp_url = "smtps://my_tinet_user@smtp.t1net.cat:465/" set smtp_pass = "my_tinet_pwd" set folder = "imaps://imap.t1net.cat:993" ; compte : tinet no te servei IMAP, nomes POP set spoolfile = "+INBOX" set header_cache = "/home/my_linux_user/.mutt/cache/headers" set message_cachedir = "/home/my_linux_user/.mutt/cache/bodies" set certificate_file = "/home/my_linux_user/.mutt/certificates" set ssl_verify_host = no set ssl_verify_dates = no set mail_check = 120 set move = no set imap_keepalive = 900 set sort = threads set editor = "vi" # do not write all messages to the "sent" file set copy = no

training tutorials

mutt send minim

Per comprovar que mutt funciona, engegarem aquesta comanda :

echo "my BODY" | mutt -s "my SUBJECT" -- manel@yandex.com echo "my BODY" | mutt -d 5 -s "my SUBJECT" -- destinations@gmail.com # see file ~/.muttdebug0 - level "2" is recommended

Un exemple mes "real" (2 destinataris, 2 fitxers adjunts) es aquest :

pi@odin:~/sendemail $ cat mail_mutt.sh #!/bin/bash myT=$(date +%R) myFile="/home/pi/sendemail/texto.txt" myFile2="/home/pi/sendemail/texto2.txt" szCos="el meu cos ('$myT') s'apropa" szSbj="qui es el subjecte de la feina" szDesti="unouno@gmail.com, dosdos@gmx.com, tretre@yandex.com" echo "$szCos" | mutt -s "$szSbj" -a "$myFile" -a "$myFile2" -- $szDesti rv=$? echo "mutt rc = " $rv exit 0

Molt de compte amb les dobles cometes del Subject i del Append

mutt debug

Enable debug by adding "-d 5" to "mutt" command: "mutt -d 5 <etc>"

The file is ~/.muttdebug0

debug tips

Verify you have Debug enabled at compilation time with

sebas@pi0alby:/var/log $ mutt -v | grep DEBUG +DEBUG
mutt settings

Get complete list with

$ mutt -D or more specific with mutt -D | grep use_gpg
missatge de error - GPGME: CMS protocol not available

No fem servir gpg pero rebem el missatge "GPGME: CMS protocol not available"

sag@odin:~/eines/backup $ mutt -D | grep use_gpg GPGME: CMS protocol not available crypt_use_gpgme is set pgp_use_gpg_agent is unset

Launch mutt with option '-e "set crypt_use_gpgme=no"'

Podremos optar por instalar el paquete correspondiente: "apt-get install gpgsm"
O bien por deshabilitar el uso de GPGME en /etc/Muttrc.d/gpg.rc modificando:

set crypt_use_gpgme=yes en set crypt_use_gpgme=no

Ignorem el missatge

mutt fa backup de 1 fitxer

Codi a minie :

sebas@minie:~/eines$ cat 6_save_file_2_email.sh #!/bin/bash myT=$(date +%R) myFile1="default filename" if [ $# -eq 0 ] then echo "--- No arguments supplied" exit 1 else myFile1=$1 fi echo ">>> backup by email of file " $myFile1 szCos="('$myT') cos x1 fitxer" szSbj="('$myT') backup x1 fitxer" szDesti="manel@yandex.com, sveta@aol.com" echo "$szCos" | mutt -s "$szSbj" -a "$myFile1" -- $szDesti rv=$? echo "mutt rc = " $rv exit 0
mutt fa backup dels fitxers importants

A diferents llocs fem un TGZ dels fitxers importants que tenim en una llista :

I el shell que fem servir per fer backup es troba aqui :

Crec que tothom ha de salvar minimament aixo : (see also r3 llista fitxers)

$ cat llista_fitxers.txt # eskelet per tothom /boot/config.txt /boot/firmware/config.txt /etc/apt/sources.list /etc/dhcpcd.conf /etc/hosts /etc/Muttrc # /etc/motd /etc/network/interfaces /etc/NetworkManager/NetworkManager.conf /etc/netplan/50-cloud-init.yaml /etc/rc.local /etc/resolv.conf /etc/ssh/sshd_banner.txt /etc/ssh/sshd_config /etc/systemd/system/my_bot.service # r0 /etc/systemd/system/rpz_start.service # r0 -> rpz_start.sh /home/pi/.bash_aliases /home/pi/.config/systemd/user/fronius_nodejs.service # r0 /home/pi/.config/systemd/user/fronius_poll.service # r4 /home/pi/.config/systemd/user/ping_fronius.service # r4 /home/pi/.config/systemd/user/r4_bot.service # r4 /home/pi/.config/systemd/user/r4_start.service # r4 -> r4_start.sh /home/pi/duckdns/duck.sh # r0 r3 r4 /home/pi/eines/backup/cron_values.txt # r0 <- /home/pi/eines/backup/fer_backup.sh /home/pi/eines/fer_backup.sh # r3 /home/pi/eines/llista_fitxers.txt # r3 /home/pi/eines/rpz_start.sh # r0 <- rpz_start.service /home/pi/eines/r4_start.sh # r4 /home/pi/logs/1_netejar.sh # r0 /home/sebas/eines/backup/fer_backup.sh # ? /home/sebas/eines/backup/llista_fitxers.txt # ? /home/sebas/eines/duckdns/duck.sh # minie /usr/bin/odin_restart # r3 /usr/local/bin/motd # /usr/local/bin/pi0_start # r0 <- /etc/rc.local {anulat}

email management

We want to automate some actions based on emails we receive.

The idea comes from Majordomo, a mailing list manager (MLM) written in Perl. doxfer , Homepage, FAQs

Python Majordomo using imap.py - first steps

Python has imaplib, a IMAP4 protocol client

So, using python we can easily list the Subject of all messages in a server's folder :

pi@raspberrypi-llovet:~/email_read $ cat imap.py {pi@odin:/home/pi/eines/} #!/usr/bin/python # http://stackoverflow.com/questions/348392/receive-and-send-emails-in-python # https://docs.python.org/3/library/imaplib.html # https://stackoverflow.com/questions/1009860/command-line-arguments-in-python import imaplib import sys # set default values my_user = 'myusr@gmail.com' my_pwd = 'mypwd' my_box = 'inbox' my_server = 'pop.gmail.com' # use command line params if available print( '++++++++++++++++++++ Got ('+ str( len(sys.argv)) +') params.' ) if len(sys.argv) >= 1: my_user = str( sys.argv[1] ) if len(sys.argv) >= 2: my_pwd = str( sys.argv[2] ) if len(sys.argv) >= 3: my_box = str( sys.argv[3] ) if len(sys.argv) >= 4: my_server = str( sys.argv[4] ) # display values to use print( '++++++++++++++++++++++++++++++++++++++++ User (' + my_user + ').' ) print( '++++++++++++++++++++++++++++++++++++++++ Pwd (' + my_pwd + ').' ) print( '++++++++++++++++++++++++++++++++++++++++ Box (' + my_box + ').' ) print( '++++++++++++++++++++++++++++++++++++++++ Server (' + my_server + ').' ) print( '(1) *** connect to imap server' mmail = imaplib.IMAP4_SSL( my_server ) print( '(2) *** login to user (%s)' % my_user ) mmail.login( my_user, my_pwd ) print( '(3) *** list' ) mmail.list() # Out: list of "folders" aka labels in gmail. stat, nummsg = mmail.select( my_box ) # connect to inbox (or "rsp3") szNumMsg = str(nummsg) print( 'Tenim ' + szNumMsg + ' msg' ) result, data = mmail.search( None, "ALL" ) print( 'Select ' + str( data ) + ' msg' ) ids = data[0] # data is a list. print( 'IDS (' + ids + ').' ) id_list = ids.split() # ids is a space separated string # print( 'ID LIST (' + id_list + ').' ) for num in id_list: print( 'Msg ID is (%s).' % num ) result, data = mmail.fetch( num, "(RFC822)" ) # fetch the email body (RFC822) for the given ID raw_email = data[0][1] # here's the body, which is raw text of the whole email including headers and alternate payloads import email email_message = email.message_from_string( raw_email ) print( email_message['Subject'] ) print( 'close' ) mmail.close() print( 'logout - shutdown connection to server' ) mmail.logout()

Mind imap tools : github, pypi docu

from imap_tools import MailBox # python3 -m pip install imap_tools # Get date, subject and body len of all emails from INBOX folder with MailBox('imap.mail.com').login('test@mail.com', 'pwd') as mbox: for msg in mbox.fetch(): print(msg.date, msg.subject, len(msg.text or msg.html))

old mail

When you exit the "mail" command and some messages were not deleted, you get the message :

Saved 6 messages in /home/nicolau/mbox Held 0 messages in /var/mail/nicolau

You can review old emails by :

nicolau@mars:~$ mail -f ~/mbox

Tinet

Acces al email :
Tipus de servidor de Tinet: POP (Tinet no ofereix servei IMAP)

Aixi, no podem accedir al correu de Tinet des python amb imap.py

Punt d'entrada : URL

Active http://www.fut.es/~bttt/cgi-bin/bnbform.cgi

verify Tinet email account is available

Podem verificar que el correu es actiu si hi podem escriure amb ...

sebas@minie:~$ cd /home/sebas/eines sebas@minie:~/eines$ ./3_email_a_tinet.sh

... i si hi podem llegir el correu amb ...

/home/sebas/dades/python/email/read_pop_mail/tinet_bttt.py
access Tinet using poplib

poplib specs


BLAT / SendEmail
 BLAT -INSTALL user.branch.country.company.com  foo@bar.com
 BLAT MYFILE.TXT -to destination@com.es

Tinet :

 Incoming POP Server = pop3.tinet.org (port 110)
 Outgoing SMTP Server = smtp.tinet.org (port 25)

On puc trobar un servidor de SMTP ? (as EXIM for Linux) HotBot :

To use Blat you must make sure that you have access to a SMTP server via TCP-IP.

Com saber que el servidor de correu sortint està funcionant ?

 netstat -an | grep 25

Com es fa servir ?

 Syntax: c:\blat\blat.exe msg_body_file -t recipient -server mailserver -f sender -s subject

 Example -
 Mail server="smtp.mymail43.com",
 recipient="test@mymail43.com",
 subject="Error",
 Body of e-mail=contents of file "body.txt" and
 sender=same as recipient (most mail servers requires an existing sender address)

 BLAT.EXE body.txt -t test@mymail43.com -server smtp.mymail43.com -f test@mymail43.com -s Error

Amunt! Top Amunt!
SendEmail - sending eMail from Guindous

Homepage

SENDEMAIL    -f src@dom.com    -t desti@dot.com    -u Subj    -a file1.txt
             -m message-file=FILE2.TXT   -s d06ml801.portsmouth.uk.abc.com
Amunt! Top Amunt!
using GMAIL

Incoming Mail (POP3) Server - requires SSL: pop.gmail.com Use SSL: Yes Port: 995 Outgoing Mail (SMTP) Server - requires TLS or SSL: smtp.gmail.com (use authentication) Use Authentication: Yes Port for TLS/STARTTLS: 587 Port for SSL: 465

url

You have to download the "TLS supported" version from here

SENDEMAIL -f from_sag@tinet.org -t nom_desti@hp.com -cc segon@pp.com -bcc tercer@qq.com -u Pic003 -a DSC01993.JPG -m message-file=FILE2.TXT -s d06ml801.portsmouth.uk.abc.com -f FROM address -t TO address address address -cc CC address address address -bcc BCC address address address -u Subject -a Attach a File -m Message body -s SMTP mail relay

T42:\eMail\SendEmail\sendEmail-v155\
SENDEMAIL    -f from@dom.com    -t desti@dot.com    -cc copia@dom.com    -bcc  copia_oculta@dom.com   -u Subj    -a file1.txt
             -m message-file=FILE2.TXT   -s tinet.smtp    -xu tinet.user    -xp tinet.clau
@echo off SET USR=gmailuser SET PWD=gmailpwd SET SRC=origin_user@gmail.com SET DST=destination_user@gmail.com SET CCOPY=copied_user@domain.com SET BCCCPY=blind_copied@dom.com SET SBJ="subjecte de la carta" SET MSG="msg body" SET SVR=smtp.gmail.com SET ATX=F1.TXT SENDEMAIL -f %SRC% -t %DST% -cc %CCOPY% -bcc %BCCCPY% -u %SBJ% -m %MSG% -s %SVR% -a %ATX% -xu %USR% -xp %PWD%

June 2010 :

Jun 27 11:43:53 sap200xpsp3 SENDEMAIL[7216]: NOTICE => Authentication not supported by the remote SMTP server! Jun 27 11:43:53 sap200xpsp3 SENDEMAIL[7216]: ERROR => Received: 530 5.7.0 Must issue a STARTTLS command first.

April 2017 :

c:\eines> sndemail.cmd Apr 02 14:42:39 w500-w2008r2 sendEmail.exe[3060]: Email was sent successfully!
Amunt! Top Amunt!
Linux install

Install sendemail in debian lenny

#apt-get install sendemail

url

Complete debug email
pi@odin:~/sendemail $ cat snd_1.sh #!/bin/bash # do send an EMAIL # called from 2 places : # 1 - /etc/network/if-up.d/envia_emilio # 2 - crontab root user - /home/pi/eines/cron_feina_send_email.sh log_file="/home/pi/logs/send_emilio.log" echo "Trace filesystem status into a file" >> $log_file myfn=/home/pi/logs/df.log echo "Generated by /home/pi/sendemail/snd_1.sh" > $myfn echo "******** ******** filesystem *" >> $myfn df -h >> $myfn echo "******** ******** wifi name *" >> $myfn iwconfig >> $myfn date_name=`date +"y%y/m%m/d%d"` time_name=`date +"h%H:m%M"` echo "Get wifi name" nom_wifi=$(/sbin/iwgetid) echo "Get external IP" >> $log_file ipvariable=$(curl -m 2 -s icanhazip.com); ipvariable=$(curl -m 2 -s http://checkip.amazonaws.com); rc1=$? echo ">>> (2) icanhazip rc ($rc1)" >> $log_file echo "Get internal IP" >> $log_file myip="$(/sbin/ifconfig wlan0 | grep 'inet addr:192' | cut -d: -f2 | awk '{ print $1}')" szIP="Today IPs : external {$ipvariable}, internal {$myip}." echo "Send an email with 2 files attached" >> $log_file szOut='ODIN-002, date ('$date_name'), time ('$time_name'), host ('$HOSTNAME'), wifi ('$nom_wifi'), shell ('$0'), ip ext ('$ipvariable').' desti_sebas='b1sc2k9@gmail.com' desti_llovet='11ovetbasura@gmail.com' mydoc=/home/pi/semafor/3_manual_usuari.txt echo "Enviem Subject" $szOut >> $log_file echo $szIP | mail --attach=$myfn --attach=$mydoc -s "$szOut" $desti_llovet, $desti_sebas echo "Si hi ha problemes, revisa /var/log/mail.log, /var/log/mail.err i" $log_file

Using TELNET to send SMTP commands

The first thing to do is to open a connection from your computer to your mail server.

telnet mail.domain.ext 25

You should receive a reply like:

Trying ???.???.???.???... Connected to mail.domain.ext. Escape character is '^]'. 220 mail.domain.ext ESMTP Sendmail ?version-number?; ?date+time+gmtoffset?

You will then need to declare where you are sending the email from:

HELO local.domain.name

Dont worry too much about your local domain name although you really should use your exact fully qualified domain name as seen by the outside world. The mail server has no choice but to take your word for it as of RFC822-RFC1123.

This should give you:

250 mail.domain.ext Hello local.domain.name [loc.al.i.p], pleased to meet you

Now give your email address:

MAIL FROM: mail@domain.ext

Should yield:

250 2.1.0 mail@domain.ext... Sender ok

Now give the recipients address:

RCPT TO: mail@otherdomain.ext

Should yield:

250 2.1.0 mail@otherdomain.ext... Recipient ok

To start composing the message issue the command DATA
If you want a subject for your email type

DATA Subject:-type subject here-
then press enter twice (these are needed to conform to RFC 882)

You may now proceed to type the body of your message (e.g. hello mail@otherdomain.ext from mail@domain.ext)

To tell the mail server that you have completed the message enter a single "." on a line on it's own. The mail server should reply with:

250 2.0.0 ???????? Message accepted for delivery

You can close the connection by issuing the QUIT command. The mailserver should reply with something like:

QUIT 221 2.0.0 mail.domain.ext closing connection Connection closed by foreign host.

Here are a list of problems I've encountered and their fixes :

501 nouser@nosuchplace.here... Sender domain must exist The domain that you are sending from must exist 503 Need MAIL before RCPT A recipient has been specified before a sender. 550 mail@domain.ext... Relaying Denied The mail server has refused to relay mail for you, this may be for any number of reasons but typical resons include: Not using this provider for an internet connection and/or Not using an email address provided by the owner of the server.

url

Com es posa un Attach ?

El Telnet no és un "MIME compliant" mail client.

Guideline on writing sensible email messages

url


Meigas

Error dels Emilios ?

Obre aquesta pàgina. Fixat-hi que hi ha un "." (punt) al final de la URL. Copia la URL en un Emilio. Envia'l. En rebre'l, el "punt" haurà desaparegut automàgicament.

Comprobat amb :

Eudora ? Encara no ...

Això ho ha descobert .. en Toni !


Ed uses :

bash shell script plus smtpclient.exe -- a open source SMTP connection and send utility.


Free Email Services

  1. Gmail
  2. Zoho
  3. AIM mail
  4. GMX mail
  5. Yahoo! mail - http://mail.yahoo.com/
  6. Gawab.com
  7. Inbox.com
  8. FastMail
  9. Hotmail
  10. Lycos (tf required)
  11. MyWay
  12. HushMail (expires if not used)

10 best


Errors, tricks, ...


public servers configuration

We shall work with these providers :

Other providers and why we dont use them :

Gmail configuration
enable IMAP in your Gmail settings

  1. go to Gmail in your web browser
  2. click on the Gear icon (Settings) in the top right corner and select "See all settings"
  3. go to the "Forwarding and POP/IMAP" tab
  4. under "IMAP access," make sure "IMAP is enabled" is selected
  5. click "Save Changes" at the bottom
generate APP password

If you have 2FA enabled on your Google account (highly recommended!), you must generate an App Password to use with Mutt. You cannot use your regular Google account password directly. This provides an extra layer of security.

If you don't use 2-Step Verification, Google historically allowed "Less secure app access." However, this option is being phased out or already removed for many accounts due to security concerns.

Generate a Google App Password (if you use 2FA):

  1. go to your Google Account Security page {and turn-on 2-step verification}
  2. under "Signing in to Google," if you have 2-Step Verification enabled, you'll see "App passwords." Click on it.
  3. in "Security" under "Signing in to Google," click on (or search for) "App passwords." You might need to sign in again.
  4. select "Mail" for the app and "Other (Custom name)" for the device. You can name it "Mutt" or anything you prefer.
  5. click "Generate."
  6. Google will display a 16-character password. Copy this password immediately, as it will only be shown once. This is the password you will use in your Mutt configuration, not your regular Google password.
Free Gmail SMPT server

siteground

configure Mutt at Minie to send email from bash

We start with Gemini "configure gmail smtp access from mutt"
Sometimes it insists on using ssmtp or msmtp MTA agents

sebas@minie:~$ cat /etc/Muttrc ## SAG, 20250717 set from = "bcn.borinot@gmail.com" set realname = "Mutt at Minie" # SMTP - enviar correu set smtp_url = "smtp://bcn.borinot@gmail.com@smtp.gmail.com:587/" # using port 587 for TLS set smtp_pass = "olpv cdhv jxfg mljl" # use TLS for secure connection set ssl_starttls = yes set ssl_force_tls = yes # Authentication method (usually login) set smtp_authenticators = 'login'

Proves :

Without APP password : "535-5.7.8 Username and Password not accepted."

With APP password : OK

YANDEX configuration

To access the yandex email from an app, you have to get a special password : url

old configuration :

If you receive the message “Username failure or POP3/IMAP disabled”, the mail program cannot access the mailbox over POP3/IMAP. Make sure your email account password is correct and POP3/IMAP is enabled in the Email clients section.

APP password

  1. open security tab
  2. in the Access to your data section, select App passwords
  3. under Create an app password, choose the app type - I use "Email address"

Yandex help

GMX configuration

We want to access gmx using python from MARS

20200720 - cant access gmx using IMAP (but POP3 is fine) - email support

"user" field must include the domain : "user@gmx.com" !

AOL configuration

Homepage

APP password

  1. go to Security page
  2. click "Generate" or "Manage"
PROTON email

Proton email, drive 2 GB

To use SMTP server, you need ProtonMail Bridge, an App on your PC

TUTA email

Tuta -> TutaMail - cifrado, bloquean rastreadores ... 1 GB storage


Pending


Amunt! Top Amunt!
Links


Ep ! Valid HTML 4.01! Site under construction. Escriu-me !
Updated 20190504  
Uf !