Giter Site home page Giter Site logo

smtp-cli's Introduction

smtp-cli — command line SMTP client

smtp-cli is a powerful SMTP command line client with a support for advanced features, such as STARTTLS, SMTP-AUTH, or IPv6 and with a scriptable message composition capabilities supporting anything from simple plain-text messages right up to building complex HTML emails with alternative plain-text part, attachments and inline images. The MIME-Type of the attachments can either be guessed automatically or alternatively set on the command line, separately for each attachment if required.

It's also a convenient tool for testing and debugging SMTP servers setups. Even the hardcore mail admins used to typing the SMTP protocol over telnet need a specialised tool when it comes to verifying encryption settings of their TLS enabled server with a subsequent user authentication. Such things are pretty hard to type into a telnet session by hand :-)

The name smtp-cli stands for:

  1. smtp-client
  2. Smtp-command Line Interface

Use smtp-cli if you want to:

  1. check mail server capabilities
  2. test the server setup
  3. create and send complex emails from scripts or cron-jobs

The smtp-cli usage is intuitive, everything is scriptable and can run in a completely non-interactive mode from various scripts or cron jobs. It is also ideal for shipping log files from remote machines, running periodical mail delivery test loops, etc. Also if you ever needed to send a complex email with attachments from a command line, this script is all you need.

Installation

Download the latest release from smtp-cli on GitHub and make it executable:

~ $ wget -o smtp-cli https://github.com/mludvig/smtp-cli/releases/{LATEST_RELEASE}
~ $ chmod +x smtp-cli

Optional dependencies

Some features of smtp-cli are optional and available only when the appropriate perl modules are installed:

  • RedHat Enterprise (RHEL), Fedora, Oracle Linux and CentOS users may want to install the following packages:

    $ sudo yum install  perl-IO-Socket-SSL  perl-Digest-HMAC  perl-TermReadKey  \
                          perl-MIME-Lite  perl-File-LibMagic  perl-IO-Socket-INET6

    If yum can't find them all try to enable EPEL repository.

  • openSUSE and SUSE Enterprise (SLES) users should install these packages:

    $ sudo zypper install  perl-IO-Socket-SSL  perl-Digest-HMAC  perl-TermReadKey  \
                             perl-MIME-Lite  perl-File-LibMagic  perl-IO-Socket-INET6
  • Users of Debian, Ubuntu and derivates should install these packages:

    $ sudo apt install  libio-socket-ssl-perl  libdigest-hmac-perl  libterm-readkey-perl \
                          libmime-lite-perl libfile-libmagic-perl libio-socket-inet6-perl

Users of other Linux distributions will have to find the appropriate packages by themselves, or install the modules directly from CPAN.

Donate please :)

Please consider donating, even if it's just enough for a coffee.

Donate with PayPal

Usage examples

These examples are for testing and verifying mail servers configurations:

Example 1 - Test your localhost

The simplest example - it will not actually send anything. Only connect to a server, do some SMTP chatting and disconnect.

$ ./smtp-cli --verbose --server localhost
[220] 'localhost ESMTP Postfix'
> EHLO localhost
[250] 'localhost'
[250] 'PIPELINING'
[250] 'SIZE 20480000'
[250] 'ETRN'
[250] '8BITMIME'
> QUIT
[221] 'Bye'

Example 2 - Send an e-mail through a host which requires encryption and authentication

Things are getting more interesting. We will use --server smtp.example.com:587 to connect to port 587 that is usually used by email clients (port 25 is usually for server-to-server communication). Port 587 also usually requires authentication.

For that we'll supply --user test and optional --password ... to supply the credentials. If the password is not supplied we will be asked interactively.

To actually send something we will also supply --from and --to parameters and also --data message.txt.

Note tat this message.txt must contain both the headers and the message body. If you don't want to bother with creating the message headers yourself use --body instead, see the next example for details.

$ ./smtp-cli --verbose --host smtp.example.com:587 --enable-auth --user test \
--from [email protected] --to [email protected] --data message.txt

[220] 'smtp.example.com ESMTP Postfix'
> EHLO localhost
[250] 'smtp.example.com'
[250] 'PIPELINING'
[250] 'SIZE 10240000'
[250] 'VRFY'
[250] 'ETRN'
[250] 'STARTTLS'
[250] 'XVERP'
[250] '8BITMIME'
Starting TLS...
> STARTTLS
[220] 'Ready to start TLS'
Using cipher: EDH-RSA-DES-CBC3-SHA
Subject Name: /C=XX/CN=smtp.example.com/[email protected]
Issuer  Name: /C=XX/CN=Example.COM Root CA/[email protected]
> EHLO localhost
[250] 'smtp.example.com'
[250] 'PIPELINING'
[250] 'SIZE 10240000'
[250] 'VRFY'
[250] 'ETRN'
[250] 'AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5'
[250] 'AUTH=PLAIN LOGIN DIGEST-MD5 CRAM-MD5'
[250] 'XVERP'
[250] '8BITMIME'
AUTH method (PLAIN LOGIN DIGEST-MD5 CRAM-MD5): using CRAM-MD5
> AUTH CRAM-MD5
[334] 'PDE0OTQyOTcxOC4yNjAwOTYwQHNlcnZlci5kb21haW4udG9wPg=='
> dGVzdCBmOTUyY2RkM2VlODBiMzk1YjYxNDI4NjBlYzg2Y2ExZnJvb3Q=
[235] 'Authentication successful'
Authentication of test@localhost succeeded
> MAIL FROM: <[email protected]>
[250] 'Ok'
> RCPT TO: <[email protected]>
[250] 'Ok'
> DATA
[354] 'End data with <CR><LF>.<CR><LF>'
[250] 'Ok: queued as C5C3A299D7'
> QUIT
[221] 'Bye'

Example 3 - Compose a plain text email with attachments

For composing emails you will need an optional MIME::Lite perl module. See the Optional dependencies section above for details.

$ ./smtp-cli [--server / --auth / --verbose flags] \
             --from [email protected] --to [email protected] \
             --subject "Simple test with attachments" \
             --body-plain "Log files are attached." \
             --attach /var/log/some.log@text/plain \
             --attach /var/log/other.log

This example composes a standard plain text email with two attachments. The interesting part is the syntax used for enforcing MIME-Type of the first attachment.

The syntax some.log@text/plain will make some.log attached as text/plain part, while the MIME-Type of other.log will be guessed by the script and eventually default to application/octet-stream.

Example 4 - Attachment as an email body

$ ./smtp-cli [--server / --auth / --verbose flags] \
             --from [email protected] --to [email protected] \
             --subject "Image as a mail body" \
             --attach /path/to/tux.png

If there is only one text or image file to be sent, the file itself could be the message body. At the same time it will be accessible as an attachment with a file name for easy saving. Best to show a screenshot I guess...

Attachment as an email body

There is no Text or HTML body part and the email is not multipart/mixed. All that is in the email is Tux the Penguin image. You can immediately see it in your mailer but also can easily save it with its provided name tux.png. The same way it works with text files (or files forced to be text/plain, to be precise).

Example 5 - Compose a multipart/alternative email with both HTML and Plain text part and inline images

Sending HTML emails is popular, especially among non-technical people. They like to change font colours, backgrounds, embed images and apply all sorts of other useless effects to their one short line of text. Indeed, me and you are more than happy with plain text and we both know that some mail readers can't even display colours and graphics at all (our office manager wouldn't believe!). Therefore it is a good practice for HTML messages to use multipart/alternative MIME format with both HTML and TEXT parts. In this example we're going to go wild and even embed an inlined image or two into the HTML part.

First of all prepare the message body. Or bodies, actually. The HTML one is body.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head></head>
<body bgcolor="#ffffff" text="#000000">
<div align="center">
Here comes embedded <font color="#006600"><b>Mr Tux</b></font><br>
<img src="cid:tux.png"><br>
<i>Nice, isn't it?</i><br>
<img src="cid:smiley.png"><br>
</div>
</body>
</html>

Note the <img> tags with cid:filename.xyz source — that's the way to refer inlined attachments from inside the message. We will obviously have to inline-attach tux.png and smiley.png to the message to make it work.

The second body file is a plain text representation of the above, call it body.txt:

Here comes embedded Mr Tux
... actually it doesn't ... 
Not in a text-only mail reader.
Sorry

That's it. Here comes the magic command line that puts it all together:

$ ./smtp-cli --from [email protected] --to [email protected] \
             --subject "HTML with embedded image" \
             --body-html body.html --body-plain body.txt \
             --attach-inline tux.png --attach-inline smiley.png

And this is what we get:

Multipart HTML email with embedded image

Donate please :)

Please consider donating, even if it's just enough for a coffee.

Donate with PayPal

Author

Michael Ludvig - get in touch through the Issues section above.

smtp-cli's People

Contributors

derdakon avatar mludvig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smtp-cli's Issues

exit codes are wrong

1 is returned on success and on the two most common errors. 0 is returned on all other errors.

perhaps you should revert 3545319, going back to 'return 1' for success, and 'return 0' for error.
then simply do this:

my $smtp_success = run_smtp;
my $exit_code = $smtp_success ? 0 : 125;
exit $exit_code;

Very Minor Issue

for 3.9, version is reported as 3.8
Clearly, author forgot to change the version value.
Simple fix.

STARTTLS over port 25 failes with error:1408F10B:SSL

Trying to send the mail via mail relay which only support 1.1 & 1.2 TLS fails with this message,

SSL/TLS: SSL connect attempt failed error:1408F10B:SSL routines:ssl3_get_record:wrong version number

running this command:

smtp-cli --server=mx3 --ipv4 --verbose \
             --from=XXX \
             --to=YYYY \
             --subject="TEST" \
             --body-plain=/etc/os-release \
             --ssl

Connection from 4.3.2.1:57890 to 1.2.3.4:25
Starting SMTP/SSL...
687 SSL/TLS: SSL connect attempt failed error:1408F10B:SSL routines:ssl3_get_record:wrong version number

"Smartmatch is experimental" warning in perl 5.18

As of perl 5.18, the smartmatch_family_of_features_are_now_experimental.

As a result, running smtp-cli in perl 5.18 emits a warning:

Smartmatch is experimental at ... line 254

Per the docs:

Warnings will now be issued when the parser sees ~~, given, or when. To disable these warnings, you can add this line to the appropriate scope:

no if $] >= 5.018, "experimental::smartmatch";

Consider, though, replacing the use of these features, as they may change behavior again before becoming stable.

I would submit a pull request with the warning muted, but I think it's probably better not to paper over this =)

socket timeout fails on older versions of IO::Socket::SSL

i need to remove the timeout to get this to work on a Nokia N9.
IO::Socket 1.33 {libio-socket-ssl-perl_1.33-1+squeeze1_all.deb}
Net::SSLeay 1.36 {libnet-ssleay-perl_1.36-1_armel.deb}

a good workaround, i think, would be to add a CLI option to remove the Timeout => 5 from the socket {--no-socket-timeout}. what do you think of this approach?

without removing the timeout, i get this:
SSL/TLS: SSL connect attempt failed with unknown error error:00000000:lib(0):func(0):reason(0)

with the timeout removed from the script, it works like a charm. note that the errors happen instantly, for whatever reason, not after 5 seconds, and with the timeout removed, the socket connects in a few milliseconds.

option --ipv4 kicks IO::Socket::INET6

Despite passing --ipv4 at command line, the code tries to initiate ipv6 socket.

By changing line 409:
if ($addr_family == AF_INET6) {

The code works as expected

socket timeout fails on older versions of IO::Socket::SSL

i need to remove the timeout to get this to work on a Nokia N9.
IO::Socket 1.33 {libio-socket-ssl-perl_1.33-1+squeeze1_all.deb}
Net::SSLeay 1.36 {libnet-ssleay-perl_1.36-1_armel.deb}

a good workaround, i think, would be to add a CLI option to remove the Timeout => 5 from the socket {--no-socket-timeout}. what do you think of this approach?

without removing the timeout, i get this:
SSL/TLS: SSL connect attempt failed with unknown error error:00000000:lib(0):func(0):reason(0)

with the timeout removed from the script, it works like a charm. note that the errors happen instantly, for whatever reason, not after 5 seconds, and with the timeout removed, the socket connects in a few milliseconds.

UTF-8 support for subjects (RFC 1342)

Hello. Thanks for your great script!
Can you please add support for non-latin characters in email subject?
Here are some details about that.

Of course right now we still can achieve that by providing already encoded subject to smpt-cli, but it'd be really nice to do that on the fly.

print instead of warn

Hello,

To allow comparisons within a bash script you should replace WARN with PRINT otherwise no comparisons are possible within a bash script.

In any case, I have now manually changed this for me.

LFCR in the plain text field

Hi,

how a LFCR can be added to the body-plain text field?

... --body-plain "Hi\r\n here is some text\r\n Bye"

\r\n in the provided example does not work.

P.S. thank you for the great tool!

Only being able to use mailgun.org without --force-ehlo

Hi, I am trying to use mailgun.com (they user mailgun.org for some email), and it seems that smpt-cli detects the server as SMTP only, because it's using always HELO instead of EHLO altough the server seems to be compliant

Trying to detect capabilities with telnet

$ telnet smtp.eu.mailgun.org 587
Trying 34.95.107.114...
Connected to smtp.eu.mailgun.org.
Escape character is '^]'.
220 Mailgun Influx ready
EHLO
250-4e119dd77b0c
250-AUTH PLAIN LOGIN
250-SIZE 52428800
250-8BITMIME
250-SMTPUTF8
250-PIPELINING
250 STARTTLS
./smtp-cli --server=smtp.eu.mailgun.org:587      [email protected] --pass=xxxx   --verbose  --from [email protected] --to [email protected]  --subject "Simple test with attachments"              --body-plain "Log files are attached."              --attach /tmp/file.txt
[220] 'Mailgun Influx ready'
> HELO localhost
[250] '596f9cb77e29'
> MAIL FROM:<[email protected]>
[250] 'Sender address accepted'
> RCPT TO:<[email protected]>
[550] '5.7.1 Relaying denied'
RCPT TO <[email protected]> failed: '550 5.7.1 Relaying denied'
> QUIT
[221] 'See you later. Yours truly, Mailgun'

When using perl-cli with the --force-ehlo command, the emails get send without issues,

[220] 'Mailgun Influx ready'
> EHLO localhost
[250] 'bb128a7fa2d3'
[250] 'AUTH PLAIN LOGIN'
[250] 'SIZE 52428800'
[250] '8BITMIME'
[250] 'SMTPUTF8'
[250] 'PIPELINING'
[250] 'STARTTLS'
Starting TLS...
> STARTTLS
[220] 'Go ahead'
Using cipher: TLS_AES_128_GCM_SHA256
Subject Name: /C=US/ST=Texas/L=San Antonio/O=MAILGUN TECHNOLOGIES, INC/CN=*.eu.mailgun.org
Issuer  Name: /C=US/O=DigiCert Inc/CN=DigiCert TLS RSA SHA256 2020 CA1
> EHLO localhost
[250] 'bb128a7fa2d3'
[250] 'AUTH PLAIN LOGIN'
[250] 'SIZE 52428800'
[250] '8BITMIME'
[250] 'SMTPUTF8'
[250] 'PIPELINING'
AUTH method (PLAIN LOGIN): using LOGIN
> AUTH LOGIN
....

Related issue (with another domain here)

1 connection, multiple e-mails

There is the possibility of using a single connection for sending several emails with recipients and different messages? If so, how?

stdin mode for body

It's possible to use --data=- for STDIN, but not for --body-plain=- or --body-html=-. It would be very useful - we'll be able replace standard mail(1) with smtp-cli. --data=- takes only raw input, so it's not very useful for sending output of cron jobs and similar tasks.

Failing to send email from Ubuntu 20.04- probable password issues

I am trying to install smtp-cli in CI/CD pipeline in a container. I wrote following code in a bash script.

sudo apt-get install -y git

sudo git clone https://github.com/mludvig/smtp-cli.git

sudo apt install  libio-socket-ssl-perl  libdigest-hmac-perl  libterm-readkey-perl \
libmime-lite-perl libfile-libmagic-perl libio-socket-inet6-perl libnet-dns-perl

sudo ls -l smtp-cli

sudo chmod +x smtp-cli/smtp-cli

sudo /smtp-cli/smtp-cli --verbose --host myserver.mail.domain.com:587 --enable-auth --user '[email protected]' --password 'somepassword' --from '[email protected]' --to '[email protected]' --subject Test email from smtp-cli


Following is the output

2023-07-19T16:56:33.9551351Z ##[section]Starting: Email Task copy
2023-07-19T16:56:33.9555974Z ==============================================================================
2023-07-19T16:56:33.9556130Z Task : Bash
2023-07-19T16:56:33.9556200Z Description : Run a Bash script on macOS, Linux, or Windows
2023-07-19T16:56:33.9556326Z Version : 3.225.1
2023-07-19T16:56:33.9556399Z Author : Microsoft Corporation
2023-07-19T16:56:33.9556483Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
2023-07-19T16:56:33.9556630Z ```

2023-07-19T16:56:34.0993783Z Generating script.
2023-07-19T16:56:34.1020022Z ========================== Starting Command Output ===========================
2023-07-19T16:56:34.1040928Z [command]/usr/bin/bash /home/vsts/work/_temp/e4c23f52-488f-4e44-89d9-8149b3958dc8.sh
2023-07-19T16:56:35.0853093Z Reading package lists...
2023-07-19T16:56:35.3349300Z Building dependency tree...
2023-07-19T16:56:35.3369181Z Reading state information...
2023-07-19T16:56:35.4825801Z git is already the newest version (1:2.41.0-0ppa1~ubuntu22.04.1).
2023-07-19T16:56:35.4826727Z 0 upgraded, 0 newly installed, 0 to remove and 27 not upgraded.
2023-07-19T16:56:35.4916296Z Cloning into 'smtp-cli'...
2023-07-19T16:56:36.0364479Z
2023-07-19T16:56:36.0365189Z WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
2023-07-19T16:56:36.0366419Z
2023-07-19T16:56:36.0853886Z Reading package lists...
2023-07-19T16:56:36.2581746Z Building dependency tree...
2023-07-19T16:56:36.2592310Z Reading state information...
2023-07-19T16:56:36.4050730Z libterm-readkey-perl is already the newest version (2.38-1build4).
2023-07-19T16:56:36.4051671Z libterm-readkey-perl set to manually installed.
2023-07-19T16:56:36.4052607Z The following additional packages will be installed:
2023-07-19T16:56:36.4053155Z libauthen-sasl-perl libdigest-bubblebabble-perl libemail-date-format-perl
2023-07-19T16:56:36.4053686Z libidn12 libmailtools-perl libmime-types-perl libnet-dns-sec-perl
2023-07-19T16:56:36.4054123Z libnet-ip-perl libnet-libidn-perl libnet-smtp-ssl-perl libnet-ssleay-perl
2023-07-19T16:56:36.4056978Z libperl4-corelibs-perl libsocket6-perl perl-openssl-defaults
2023-07-19T16:56:36.4064514Z Suggested packages:
2023-07-19T16:56:36.4065286Z libgssapi-perl default-mta | mail-transport-agent libmojolicious-perl
2023-07-19T16:56:36.4595008Z The following NEW packages will be installed:
2023-07-19T16:56:36.4596055Z libauthen-sasl-perl libdigest-bubblebabble-perl libdigest-hmac-perl
2023-07-19T16:56:36.4597069Z libemail-date-format-perl libfile-libmagic-perl libidn12
2023-07-19T16:56:36.4597749Z libio-socket-inet6-perl libio-socket-ssl-perl libmailtools-perl
2023-07-19T16:56:36.4598299Z libmime-lite-perl libmime-types-perl libnet-dns-perl libnet-dns-sec-perl
2023-07-19T16:56:36.4598827Z libnet-ip-perl libnet-libidn-perl libnet-smtp-ssl-perl libnet-ssleay-perl
2023-07-19T16:56:36.4605749Z libperl4-corelibs-perl libsocket6-perl perl-openssl-defaults
2023-07-19T16:56:36.4953043Z 0 upgraded, 20 newly installed, 0 to remove and 27 not upgraded.
2023-07-19T16:56:36.5670692Z Need to get 1411 kB of archives.
2023-07-19T16:56:36.5671302Z After this operation, 4723 kB of additional disk space will be used.
2023-07-19T16:56:36.5672427Z Get:1 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libdigest-bubblebabble-perl all 0.02-2.1 [7160 B]
2023-07-19T16:56:36.5777681Z Get:2 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libdigest-hmac-perl all 1.04+dfsg-1 [10.8 kB]
2023-07-19T16:56:36.5891275Z Get:3 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libemail-date-format-perl all 1.005-1.1 [6088 B]
2023-07-19T16:56:36.5998693Z Get:4 http://azure.archive.ubuntu.com/ubuntu jammy/universe amd64 libfile-libmagic-perl amd64 1.23-1build2 [30.3 kB]
2023-07-19T16:56:36.6150684Z Get:5 http://azure.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libidn12 amd64 1.38-4ubuntu1 [60.0 kB]
2023-07-19T16:56:36.6333286Z Get:6 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libsocket6-perl amd64 0.29-1build4 [19.7 kB]
2023-07-19T16:56:36.6446752Z Get:7 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libio-socket-inet6-perl all 2.73-1 [14.7 kB]
2023-07-19T16:56:36.6561068Z Get:8 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 perl-openssl-defaults amd64 5build2 [7542 B]
2023-07-19T16:56:36.6677036Z Get:9 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libnet-ssleay-perl amd64 1.92-1build2 [327 kB]
2023-07-19T16:56:36.6991938Z Get:10 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libio-socket-ssl-perl all 2.074-2 [192 kB]
2023-07-19T16:56:36.7142264Z Get:11 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libnet-smtp-ssl-perl all 1.04-1 [5948 B]
2023-07-19T16:56:36.7327397Z Get:12 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libmailtools-perl all 2.21-1 [80.7 kB]
2023-07-19T16:56:36.7619929Z Get:13 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libmime-lite-perl all 3.033-1 [64.2 kB]
2023-07-19T16:56:36.7764177Z Get:14 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libmime-types-perl all 2.22-1 [64.3 kB]
2023-07-19T16:56:36.7899107Z Get:15 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libnet-ip-perl all 1.26-2 [27.4 kB]
2023-07-19T16:56:36.8008687Z Get:16 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libnet-dns-perl all 1.33-1 [350 kB]
2023-07-19T16:56:36.8304518Z Get:17 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libnet-dns-sec-perl amd64 1.19-1build2 [44.5 kB]
2023-07-19T16:56:36.8852177Z Get:18 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libnet-libidn-perl amd64 0.12.ds-3build6 [18.4 kB]
2023-07-19T16:56:36.8959361Z Get:19 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libperl4-corelibs-perl all 0.004-2 [37.4 kB]
2023-07-19T16:56:36.9070402Z Get:20 http://azure.archive.ubuntu.com/ubuntu jammy/main amd64 libauthen-sasl-perl all 2.1600-1.1 [43.1 kB]
2023-07-19T16:56:37.2700671Z Fetched 1411 kB in 0s (3671 kB/s)
2023-07-19T16:56:37.3031412Z Selecting previously unselected package libdigest-bubblebabble-perl.
2023-07-19T16:56:37.3228499Z (Reading database ...
2023-07-19T16:56:37.3228822Z (Reading database ... 5%
2023-07-19T16:56:37.3229026Z (Reading database ... 10%
2023-07-19T16:56:37.3229287Z (Reading database ... 15%
2023-07-19T16:56:37.3231353Z (Reading database ... 20%
2023-07-19T16:56:37.3231786Z (Reading database ... 25%
2023-07-19T16:56:37.3232178Z (Reading database ... 30%
2023-07-19T16:56:37.3232485Z (Reading database ... 35%
2023-07-19T16:56:37.3232988Z (Reading database ... 40%
2023-07-19T16:56:37.3233208Z (Reading database ... 45%
2023-07-19T16:56:37.3233406Z (Reading database ... 50%
2023-07-19T16:56:37.3494910Z (Reading database ... 55%
2023-07-19T16:56:37.3769303Z (Reading database ... 60%
2023-07-19T16:56:37.3954050Z (Reading database ... 65%
2023-07-19T16:56:37.4352690Z (Reading database ... 70%
2023-07-19T16:56:37.4782419Z (Reading database ... 75%
2023-07-19T16:56:37.5431253Z (Reading database ... 80%
2023-07-19T16:56:37.5929508Z (Reading database ... 85%
2023-07-19T16:56:37.6357911Z (Reading database ... 90%
2023-07-19T16:56:37.7088179Z (Reading database ... 95%
2023-07-19T16:56:37.7088802Z (Reading database ... 100%
2023-07-19T16:56:37.7089740Z (Reading database ... 221778 files and directories currently installed.)
2023-07-19T16:56:37.7183318Z Preparing to unpack .../00-libdigest-bubblebabble-perl_0.02-2.1_all.deb ...
2023-07-19T16:56:37.7233733Z Unpacking libdigest-bubblebabble-perl (0.02-2.1) ...
2023-07-19T16:56:37.7493501Z Selecting previously unselected package libdigest-hmac-perl.
2023-07-19T16:56:37.7673870Z Preparing to unpack .../01-libdigest-hmac-perl_1.04+dfsg-1_all.deb ...
2023-07-19T16:56:37.7681393Z Unpacking libdigest-hmac-perl (1.04+dfsg-1) ...
2023-07-19T16:56:37.7932302Z Selecting previously unselected package libemail-date-format-perl.
2023-07-19T16:56:37.8110522Z Preparing to unpack .../02-libemail-date-format-perl_1.005-1.1_all.deb ...
2023-07-19T16:56:37.8121549Z Unpacking libemail-date-format-perl (1.005-1.1) ...
2023-07-19T16:56:37.8372739Z Selecting previously unselected package libfile-libmagic-perl.
2023-07-19T16:56:37.8569990Z Preparing to unpack .../03-libfile-libmagic-perl_1.23-1build2_amd64.deb ...
2023-07-19T16:56:37.8582042Z Unpacking libfile-libmagic-perl (1.23-1build2) ...
2023-07-19T16:56:37.8933050Z Selecting previously unselected package libidn12:amd64.
2023-07-19T16:56:37.9106092Z Preparing to unpack .../04-libidn12_1.38-4ubuntu1_amd64.deb ...
2023-07-19T16:56:37.9128211Z Unpacking libidn12:amd64 (1.38-4ubuntu1) ...
2023-07-19T16:56:37.9373968Z Selecting previously unselected package libsocket6-perl.
2023-07-19T16:56:37.9563085Z Preparing to unpack .../05-libsocket6-perl_0.29-1build4_amd64.deb ...
2023-07-19T16:56:37.9573402Z Unpacking libsocket6-perl (0.29-1build4) ...
2023-07-19T16:56:37.9812880Z Selecting previously unselected package libio-socket-inet6-perl.
2023-07-19T16:56:38.0002260Z Preparing to unpack .../06-libio-socket-inet6-perl_2.73-1_all.deb ...
2023-07-19T16:56:38.0013194Z Unpacking libio-socket-inet6-perl (2.73-1) ...
2023-07-19T16:56:38.0253010Z Selecting previously unselected package perl-openssl-defaults:amd64.
2023-07-19T16:56:38.0458495Z Preparing to unpack .../07-perl-openssl-defaults_5build2_amd64.deb ...
2023-07-19T16:56:38.0465846Z Unpacking perl-openssl-defaults:amd64 (5build2) ...
2023-07-19T16:56:38.0773350Z Selecting previously unselected package libnet-ssleay-perl:amd64.
2023-07-19T16:56:38.0925123Z Preparing to unpack .../08-libnet-ssleay-perl_1.92-1build2_amd64.deb ...
2023-07-19T16:56:38.0937968Z Unpacking libnet-ssleay-perl:amd64 (1.92-1build2) ...
2023-07-19T16:56:38.1330092Z Selecting previously unselected package libio-socket-ssl-perl.
2023-07-19T16:56:38.1538621Z Preparing to unpack .../09-libio-socket-ssl-perl_2.074-2_all.deb ...
2023-07-19T16:56:38.1547006Z Unpacking libio-socket-ssl-perl (2.074-2) ...
2023-07-19T16:56:38.1808362Z Selecting previously unselected package libnet-smtp-ssl-perl.
2023-07-19T16:56:38.2042082Z Preparing to unpack .../10-libnet-smtp-ssl-perl_1.04-1_all.deb ...
2023-07-19T16:56:38.2055729Z Unpacking libnet-smtp-ssl-perl (1.04-1) ...
2023-07-19T16:56:38.2260481Z Selecting previously unselected package libmailtools-perl.
2023-07-19T16:56:38.2476689Z Preparing to unpack .../11-libmailtools-perl_2.21-1_all.deb ...
2023-07-19T16:56:38.2485059Z Unpacking libmailtools-perl (2.21-1) ...
2023-07-19T16:56:38.2810702Z Selecting previously unselected package libmime-lite-perl.
2023-07-19T16:56:38.2991146Z Preparing to unpack .../12-libmime-lite-perl_3.033-1_all.deb ...
2023-07-19T16:56:38.3001930Z Unpacking libmime-lite-perl (3.033-1) ...
2023-07-19T16:56:38.3250206Z Selecting previously unselected package libmime-types-perl.
2023-07-19T16:56:38.3442511Z Preparing to unpack .../13-libmime-types-perl_2.22-1_all.deb ...
2023-07-19T16:56:38.3459357Z Unpacking libmime-types-perl (2.22-1) ...
2023-07-19T16:56:38.3738093Z Selecting previously unselected package libnet-ip-perl.
2023-07-19T16:56:38.3954286Z Preparing to unpack .../14-libnet-ip-perl_1.26-2_all.deb ...
2023-07-19T16:56:38.3962276Z Unpacking libnet-ip-perl (1.26-2) ...
2023-07-19T16:56:38.4251354Z Selecting previously unselected package libnet-dns-perl.
2023-07-19T16:56:38.4407590Z Preparing to unpack .../15-libnet-dns-perl_1.33-1_all.deb ...
2023-07-19T16:56:38.4420829Z Unpacking libnet-dns-perl (1.33-1) ...
2023-07-19T16:56:38.4890242Z Selecting previously unselected package libnet-dns-sec-perl.
2023-07-19T16:56:38.5098055Z Preparing to unpack .../16-libnet-dns-sec-perl_1.19-1build2_amd64.deb ...
2023-07-19T16:56:38.5107258Z Unpacking libnet-dns-sec-perl (1.19-1build2) ...
2023-07-19T16:56:38.5413315Z Selecting previously unselected package libnet-libidn-perl.
2023-07-19T16:56:38.5565888Z Preparing to unpack .../17-libnet-libidn-perl_0.12.ds-3build6_amd64.deb ...
2023-07-19T16:56:38.5577200Z Unpacking libnet-libidn-perl (0.12.ds-3build6) ...
2023-07-19T16:56:38.5818199Z Selecting previously unselected package libperl4-corelibs-perl.
2023-07-19T16:56:38.6010238Z Preparing to unpack .../18-libperl4-corelibs-perl_0.004-2_all.deb ...
2023-07-19T16:56:38.6017964Z Unpacking libperl4-corelibs-perl (0.004-2) ...
2023-07-19T16:56:38.6257772Z Selecting previously unselected package libauthen-sasl-perl.
2023-07-19T16:56:38.6469452Z Preparing to unpack .../19-libauthen-sasl-perl_2.1600-1.1_all.deb ...
2023-07-19T16:56:38.6479426Z Unpacking libauthen-sasl-perl (2.1600-1.1) ...
2023-07-19T16:56:38.7019848Z Setting up libmime-types-perl (2.22-1) ...
2023-07-19T16:56:38.7056394Z Setting up libauthen-sasl-perl (2.1600-1.1) ...
2023-07-19T16:56:38.7079843Z Setting up libperl4-corelibs-perl (0.004-2) ...
2023-07-19T16:56:38.7108184Z Setting up perl-openssl-defaults:amd64 (5build2) ...
2023-07-19T16:56:38.7137803Z Setting up libdigest-hmac-perl (1.04+dfsg-1) ...
2023-07-19T16:56:38.7167621Z Setting up libsocket6-perl (0.29-1build4) ...
2023-07-19T16:56:38.7197288Z Setting up libemail-date-format-perl (1.005-1.1) ...
2023-07-19T16:56:38.7225047Z Setting up libidn12:amd64 (1.38-4ubuntu1) ...
2023-07-19T16:56:38.7252878Z Setting up libfile-libmagic-perl (1.23-1build2) ...
2023-07-19T16:56:38.7281135Z Setting up libnet-ip-perl (1.26-2) ...
2023-07-19T16:56:38.7309624Z Setting up libdigest-bubblebabble-perl (0.02-2.1) ...
2023-07-19T16:56:38.7340975Z Setting up libnet-ssleay-perl:amd64 (1.92-1build2) ...
2023-07-19T16:56:38.7367772Z Setting up libnet-dns-perl (1.33-1) ...
2023-07-19T16:56:38.7397279Z Setting up libio-socket-inet6-perl (2.73-1) ...
2023-07-19T16:56:38.7423087Z Setting up libnet-libidn-perl (0.12.ds-3build6) ...
2023-07-19T16:56:38.7449616Z Setting up libio-socket-ssl-perl (2.074-2) ...
2023-07-19T16:56:38.7484434Z Setting up libnet-dns-sec-perl (1.19-1build2) ...
2023-07-19T16:56:38.7511239Z Setting up libnet-smtp-ssl-perl (1.04-1) ...
2023-07-19T16:56:38.7536676Z Setting up libmailtools-perl (2.21-1) ...
2023-07-19T16:56:38.7560463Z Setting up libmime-lite-perl (3.033-1) ...
2023-07-19T16:56:38.7596727Z Processing triggers for man-db (2.10.2-1) ...
2023-07-19T16:56:39.1710123Z Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
2023-07-19T16:56:39.5476861Z NEEDRESTART-VER: 3.5
2023-07-19T16:56:39.8654020Z NEEDRESTART-KCUR: 5.15.0-1041-azure
2023-07-19T16:56:39.8654801Z NEEDRESTART-KEXP: 5.15.0-1041-azure
2023-07-19T16:56:39.8655401Z NEEDRESTART-KSTA: 1
2023-07-19T16:56:41.4933935Z total 52
2023-07-19T16:56:41.4934744Z -rw-r--r-- 1 root root 9981 Jul 19 16:56 README.md
2023-07-19T16:56:41.4935183Z drwxr-xr-x 2 root root 4096 Jul 19 16:56 examples
2023-07-19T16:56:41.4935600Z -rwxr-xr-x 1 root root 35023 Jul 19 16:56 smtp-cli
2023-07-19T16:56:41.5067604Z sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
2023-07-19T16:56:41.5089546Z sudo: a password is required
2023-07-19T16:56:41.5122784Z ##[error]Bash exited with code '1'.
2023-07-19T16:56:41.5135878Z ##[section]Finishing: Email Task copy


How do I successfully send email from the container? Please note that I am exremely new in bash scripting and linux commands. I am using Ubuntu 20.04 if that makes any difference.

SMTP Server Error response: [503 bad sequence of commands] when following example.

Hello,

Seems this doesn't work out of the box with this provider, even with tested correct user and password.

Tested both on CentOS 6.10 and Ubuntu 20.04 with dependencies installed (including the missing dns dependency of Ubuntu).

Any idea what would be wrong in the command ?
How to debug the exchanges between client and server ?

$ smtp-cli --verbose --host smtp.mxhichina.com --enable-auth --user '[email protected]' --password 'whatever' --from '[email protected]' --to '[email protected]' --subject 'test use smtp-cli' --body-plain=/etc/lsb-release
Connection from 10.1.2.3:48402 to 59.82.44.168:25
[220] 'smtp.aliyun-inc.com MX AliMail Server'
> HELO localhost
[250] 'Ok'
> MAIL FROM:<[email protected]>
[503] 'bad sequence of commands'
MAIL FROM <[email protected]> failed: '503 bad sequence of commands'
> QUIT
[221] 'Bye'

Thanks.

smtp-cli does not actually try to login (--force-ehlo fixes this, but not documented)

version: smtp-cli version 3.6

Testing 163.com SMTP sending but from the verbose output it never actually tries to login? I've tried a number of flags and options but without any success:

~root/bin/smtp-cli --server=applesmtp.163.com [email protected] [email protected] [email protected] --pass=PASSWORD --port=465 --ssl --subject="hello from Ricky" --body-plain="content" --verbose
Connection from 121.41.35.79:56504 to 220.181.12.17:465
Starting SMTP/SSL...
Using cipher: AES128-SHA256
Subject Name: /serialNumber=YnR7sUbvKb4d/SY/OwmmcD88FU0ZzluZ/C=CN/ST=Zhejiang/L=Hangzhou/O=NetEase (Hangzhou) Network Co., Ltd/OU=MAIL Dept./CN=*.163.com
Issuer  Name: /C=US/O=GeoTrust, Inc./CN=GeoTrust SSL CA
[220] '163.com Anti-spam GT for Coremail System (163com[20121016])'
> HELO localhost
[250] 'OK'
> MAIL FROM: <[email protected]>
[553] 'authentication is required,smtp13,EcCowECZoy+xLGNU4LXrAQ--.2290S2 1415785650'
MAIL FROM <[email protected]> failed: '553 authentication is required,smtp13,EcCowECZoy+xLGNU4LXrAQ--.2290S2 1415785650'
> QUIT
[221] 'Bye'

Another attempt:

~root/bin/smtp-cli --verbose --host=applesmtp.163.com --enable-auth --user tcvsys --from [email protected] --to [email protected] --body-plain "hello you" 
Enter password for [email protected] : 
Connection from 121.41.35.79:59954 to 220.181.12.16:25
[220] '163.com Anti-spam GT for Coremail System (163com[20121016])'
> HELO localhost
[250] 'OK'
> MAIL FROM: <[email protected]>
[553] 'authentication is required,smtp12,EMCowECZ51KDLWNU045BBw--.16S2 1415785859'
MAIL FROM <[email protected]> failed: '553 authentication is required,smtp12,EMCowECZ51KDLWNU045BBw--.16S2 1415785859'
> QUIT
[221] 'Bye'

After writing this, I found:

http://www.logix.cz/michal/devel/smtp-cli/index.xp?show_selected=1&msgid=417#feedback_form

Thanks for the patch. The problem with smtp.tom.com is, however, that the server offers 
only SMTP, not ESMTP. My client then chooses to use HELO instead of EHLO which makes 
the server to not offer any SMTP extensions like AUTH. The obvious solution is to force
using EHLO even if not detected as being supported by the server. 

I added a new --force-ehlo switch for this purpose and tested with smtp.tom.com. 
Voila, now it works!

...and indeed, that was the problem.

I think it would be helpful to provide an explicit note and an example in the documentation:

http://www.logix.cz/michal/devel/smtp-cli/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.