CLI SMTP mailer

Stuff that has yet to be sorted into a category.
Message
Author
User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

CLI SMTP mailer

#1 Post by vovchik »

Dear Puppians,

I recently compiled a tiny command line SMTP mailer that you might find useful. It can send out plain text files as well as encoded binary attachments. You could use it, for example, to automate the sending out of "proprietary" TV sat codes available on a variety of web pages. In a series of scripts, you would use wget to grab a page with recent codes, parse them to grab the codes of interest, format them for your own purposes and send them out automatically to a few friends. All this could take place automatically at regular intervals using cron. What would be particularly pleasing is that you wouldn't have to open a web browser, inspect each page manually for what you want and load a mail client such as sylpheed to do the sending. The program is also useful for mailing notifications regarding system status (e.g. sending the results of "cat /var/log/messages | grep err").

There is an email.conf file in /usr/local/etc/email that requires editing before you can run this program. Simply indicate your SMTP server and login parameters etc. and away you go. If you want to have separate system-wide and personal configurations, copy email.conf to /root/.email.conf (notice the preceding dot) and make changes to the latter. The file in /root will override the global settings.

A sample script to launch email looks like this:

Code: Select all

#!/bin/sh
p1="any_old_user@gmail.com"     # This is the "to address"
p2="-s This is my test subject" # This is the "subject"
p3="/tmp/mytext.txt"            # This is the plain text file to send as "body text"
email $p1 "$p2" < $p3
All those parameters you can change on the command line. There is a readme included and a manual page I also converted to html. Unpack the archive and have a look within /usr/local/doc/. If I get motivated, I'll write a little front-end gui and post it, but that would run counter to the entire purpose of the CLI, wouldn't it?

With kind regards,
vovchik
Attachments
email_2.5.1.tar.gz
(51.22 KiB) Downloaded 1003 times

faulkmore
Posts: 3
Joined: Thu 06 Sep 2007, 07:06

cli smtp email help request

#2 Post by faulkmore »

I tested out the cli smtp email package on puppy v2.14. I compiled it from source instead of using the provided binary. The src can be downloaded from email.cleancode.org

Installed ..... with .....
./configure --with-utc
make
make install

Editted the general configuration file for "email" located at /usr/local/etc/email/email.conf . Added just enough information so the darn should work:
* my name
* my email
* smtp server
* smtp port
* smtp login/password.

I attempted to send a test email from shell script.

Code: Select all

strMsg="The Msg"
/usr/local/bin/email -s "${strMsg}" faulkmore@mydomainname.com "This message was generated by $0"
And got the following error:

************************************

email: FATAL: Could not connect to server: smtp1.mysmtpservername.net on port: 25: No route to host

Caught an ERROR, Shutting down...

************************************
No route to host?! No route to host?! But why not?! In the standard C library there is the method gethostbyname . When ./configure is run, it says gethostbyname is available. So why can't it figure out the host. Is there something i'm missing here. Does /etc/.host have to be edited somehow.

Is puppy missing something which is preventing "email" from working?

Any help would be most appreciated. I think this is a puppy issue and not a problem with the "email" software.

Kind Regards,
Dave

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

CLI SMTP mailer

#3 Post by vovchik »

Dave,

I don't remember what configure parameters I used during compilation, but my version works on Puppy 2.10. I just tested it again and got the following message:

Code: Select all

Sending  " This is my test..."  |*******************************| 100% of 487 Bytes
E-Mail Sent
Why don't you try my binary to see whether the "-with-utc" might be to blame. Also, try to run email -t, which performs a check on the email.conf config file.

With kind regards,
vovchik

faulkmore
Posts: 3
Joined: Thu 06 Sep 2007, 07:06

Foot in mouth

#4 Post by faulkmore »

'email' works perfectly. The broadband provider is blocking port 25, so we are forced to go thru their smtp server (blame server-side spam blacklists). This is why there is "no route". I knew this, but it slipped my mind. When a script is 98% done and only one thing isn't working....i'm sure we have all been there.

Thank you for your reply and i'll try to wait at least a day before I cry out for help next time.

I changed the smtp port 25->26 and everything worked perfectly.

Next step is to enchance parsing arguments and switches. It's just not sexy enough...But this is a different topic.

Thanks for your help!!

Kind Regards,
Dave

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

Thanks for your timely posting

#5 Post by mcewanw »

I used a small CLI email program like this several years ago for sending jpeg images captured using "motion", a linux video surveillance application, to my external email account. Now that I'm doing similar stuff again with "motion" on puppy linux, it was actually on my mind that I needed to look for such a CLI email program again (but couldn't remember what I used back then). I was thus very pleased to see your forum post vovchik! Thanks greatly, you've saved me a lot of time! :-)

Pity it doesn't use TLS though (so can't send to gmail). I have come across an alternative commandline email written in Perl; I'm hoping it will be able to work with gmail but haven't had time to test it yet. You'll find it at:

http://caspian.dotconf.net/menu/Software/SendEmail/

Yes, according to its website, SendEmail can use TLS and thus access gmail accounts.

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

sendEmail seems to have perl-related problem on puppy

#6 Post by mcewanw »

Downloaded sendEmail and moved the perl executable to /usr/locl/bin as required. Ran it, but got error message. Unfortunately, I don't know Perl, so don't know what it means. Pity, because I think sendEmail has all the facilities I want. Anyone, able to help here? According to what I've now read, the error message means that the perl module Errno needs to be installed. I've found it at CPAN but now I need ExtUtils:MakeMaker to do the installing, and I need to use make to install that! I don't have any of that on my system at the moment. I'll need to download devx_xxx.sfs and take it from there!

SUCCESS! I downloaded devx_xxx.sfs (in my case devx_217.sfs) via my dialup connection overnight and when I rebooted my machine in the morning I found to my surprise that sendEmail was working without my needing to do anything else. All the missing modules were in devx_217.sfs! Not everyone probably wants to have to download devx_217.sfs just to get a commandline email program working though, so I may try and install the modules that were originally missing separately. If I manage that I'll post the details and a dotpet of everything required. Without devx_217.sfs, the error messages were as follows:

# sendEmail
Can't locate Errno.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/i486-t2-linux-gnu /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/i486-t2-linux-gnu /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i486-t2-linux-gnu /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl .) at /usr/lib/perl5/5.8.8/i486-t2-linux-gnu/IO/Socket.pm line 17.
BEGIN failed--compilation aborted at /usr/lib/perl5/5.8.8/i486-t2-linux-gnu/IO/Socket.pm line 17.
Compilation failed in require at /usr/local/bin/sendEmail line 39.
BEGIN failed--compilation aborted at /usr/local/bin/sendEmail line 39.
Last edited by mcewanw on Sun 09 Sep 2007, 02:57, edited 1 time in total.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

sendEmail also works on my system

#7 Post by vovchik »

mcewanw:

sendEmail works. Sorry that this reply isn't too helpful, but I managed to install it without too much head-scratching some time ago. Here's proof:

Code: Select all

sendEmail-1.55 by Brandon Zehm <caspian@dotconf.net>

Synopsis:  sendEmail -f ADDRESS [options]

  Required:
    -f ADDRESS                from (sender) email address
    * At least one recipient required via -t, -cc, or -bcc
    * Message body required via -m, STDIN, or -o message-file=FILE

  Common:
    -t ADDRESS [ADDR ...]     to email address(es)
    -u SUBJECT                message subject
    -m MESSAGE                message body
    -s SERVER[:PORT]          smtp mail relay, default is localhost:25

  Optional:
    -a   FILE [FILE ...]      file attachment(s)
    -cc  ADDRESS [ADDR ...]   cc  email address(es)
    -bcc ADDRESS [ADDR ...]   bcc email address(es)
    -xu  USERNAME             username for SMTP authentication
    -xp  PASSWORD             password for SMTP authentication

  Paranormal:
    -b BINDADDR[:PORT]        local host bind address
    -l LOGFILE                log to the specified file
    -v                        verbosity, use multiple times for greater effect
    -q                        be quiet (i.e. no STDOUT output)
    -o NAME=VALUE             advanced options, for details try: --help misc
        -o message-file=FILE         -o message-format=raw
        -o message-header=HEADER     -o message-charset=CHARSET
        -o reply-to=ADDRESS          -o timeout=SECONDS
        -o username=USERNAME         -o password=PASSWORD
        -o tls=<auto|yes|no>         -o fqdn=FQDN

  Help:
    --help                    the helpful overview you're reading now
    --help addressing         explain addressing and related options
    --help message            explain message body input and related options
    --help networking         explain -s, -b, etc
    --help output             explain logging and other output options
    --help misc               explain -o options, TLS, SMTP auth, and more

root$ [~]->
I seem to recall that I had to install additional modules, perhaps socket::io (or something like that). I am running Puppy with devx installed, but even so, Puppy does not have a full implementation of Perl.

regards,
vovchik

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

Re: sendEmail also works on my system

#8 Post by mcewanw »

vovchik wrote:mcewanw:

sendEmail works. Sorry that this reply isn't too helpful, but I managed to install it without too much head-scratching
No problem, vovchik. As I've since indicated in my post above, I discovered independently, when switching on my machine this morning, that sendEmail was already working (I had downloaded devx_217.sfs overnight whilst I slept!). I didn't need to add any extra modules at all - the missing ones were all in devx_217.sfs. Now I want to get it going without needing to have devx_217.sfs loaded at all. As I say, I'll produce a dotpet of the missing bits if I find the time and manage to sort it out.

Though I'm sure that djones's CLI email program from http://email.cleancode.org/, which you describe in your first post on this thread, is excellent, and requires no devx_xxx.sfs to be loaded, I think I'll be using sendEmail instead because I really need TLS support so that I can use gmail. Great that there are so many options though!

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

sendEmail works well

#9 Post by vovchik »

mcewan:

While email is not at all bad, it does, as you point out, lack TLS. I now tried sendEmail and discovered that I needed to install the following modules in order to get it to send via gmail:

Net_SSLeay.pm-1.30.tar.gz and
IO-Socket-SSL-1.08.tar.gz

Both modules are available from CPAN. They install without problems, provided the SSL lib versions match (instructions are in the README). In my case, an older version of Net_SSLeay (1.25) didn't work, so I had to get the updated version above.

My sendEmail command line for gmail looks like this:

Code: Select all

sendEmail -f gmail_user@gmail.com -t recipient@some_isp.com -u subject_line -xu gmail_user@gmail.com -xp gmail_password -s smtp.gmail.com:587 -o tls=yes -o message-file=anyfile.txt

Sep 09 12:50:42 localhost sendEmail[27414]: Email was sent successfully!
Good luck with the dotpup or dotpet.

regards,
vovchik

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#10 Post by MU »

you can install Perl-modules from comandline, at least if you have devx_2xx.sfs.
I don't know if it works without it.
http://www.murga-linux.com/puppy/viewto ... 4810#34810

So for Errno it might be:
perl -MCPAN -e 'install Errno'

This also should install dependencies.

If you get an error with the name "Errno", look for the correct name here:
http://search.cpan.org/

I entered "Errno" there, and the first link confirmed, that this is the correct name.


However a dotpup would be good, as using mcpan installs quite some MB of stuff (6 MB or so if I remember well), just to satisfy the dependencies of the installer itself.

A dotpup/Pet can be made, by adding the files with the typical name from /usr/lib/perl5/

Like
Errno.pm
Auto/whatever/Errno/stuff.txt

So files might be spread in several folders there.

Mark

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

maybe tomorrow...

#11 Post by mcewanw »

Thanks for all that, vovchik and MU. I have to sleep now, but may get back to this tomorrow if my partner doesn't kill me for spending too much time with puppy linux recently...
Today I was sidetracked because of a thread on video editing (something I'm very interested in) - http://www.murga-linux.com/puppy/viewto ... 5&start=15
I was recommending a very sophisticated non-linear video editing app called zs4 from www.zs4.net which is free for use, and for windows or linux. Since then I have downloaded it but, its a complex app, and I failed to get it to install on puppy out of the box. I suspect that will take some time so I'm hoping someone on that other thread will be tempted to take it on! :-) If they don't I'm sure I'll get back to that eventually, because I really need such an app and I don't want to rely on the windows version.

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

no success, sigh...

#12 Post by mcewanw »

vovchik wrote:mcewan:
. . . discovered that I needed to install the following modules in order to get it to send via gmail:

Net_SSLeay.pm-1.30.tar.gz and

IO-Socket-SSL-1.08.tar.gz
Both modules are available from CPAN. They install without problems, provided the SSL lib versions match (instructions are in the README). In my case, an older version of Net_SSLeay (1.25) didn't work, so I had to get the updated version above.
vovchik
[using Puppy Linux 2.17.1 and devx_217.sfs loaded]

Well... I went to CPAN and the version I found of Net-SSLEAY.pm was slightly different:

Net-SSLeay-1.32.tar.gz

Anyway, I decompressed it into a directory of its own (using Xarchive), had a quick read of the readme and ran, as that suggested:

Code: Select all

 ./Makefile.PL -t 
Apparently there were things missing because it asked:

Auto-install the 9 mandatory module(s) from CPAN? [y]

I just pressed enter and always accepted offered defaults.

At the end, the report said:

[Begin]
Warning: the following files are missing in your kit:
inc/Module/Install/PRIVATE/Net/SSLeay.pm
MANIFEST
README
TODO
Please inform the author.
Warning: prerequisite examples/*.0 0 not found.
Warning: prerequisite examples/cert.pem 0 not found.
Warning: prerequisite examples/key.pem 0 not found.
Warning: prerequisite examples/key.pem.e 0 not found.
Warning: prerequisite makecert.err 0 not found.
Warning: prerequisite makecert.out 0 not found.
Warning: prerequisite sslecho.log 0 not found.
Warning: prerequisite t/local/ptr_cast_test 0 not found.
Warning: prerequisite tcpecho.log 0 not found.
Writing Makefile for Net::SSLeay
[End]

Not knowing perl at all, I didn't have a clue, but forged ahead with:

Code: Select all

 make 
That went on for ages, apparently downloading the missing stuff from the net.

Alas, it all ended with the following error, which in the circumstances of my huge knowledge-hole leaves me lost:

[Begin]
chmod 755 blib/arch/auto/Net/SSLeay/SSLeay.so
cp SSLeay.bs blib/arch/auto/Net/SSLeay/SSLeay.bs
chmod 644 blib/arch/auto/Net/SSLeay/SSLeay.bs
Manifying blib/man3/Net::SSLeay.3
Can't open blib/man3/Net::SSLeay.3 for writing: Invalid argument
at /usr/lib/perl5/5.8.8/ExtUtils/Command/MM.pm line 132
make: *** [manifypods] Error 22
[End]

So I can't even make TLS work like alone make a dotpet of the whole sendEmail+TLS requirements! I give up on the latter for sure, it seems to me that there are many dependencies that would need to be included and, having a head full of sawdust when it comes to perl, I am not the right person to do it. Though I've been working with UNIX, to some extent, for almost 30 years, and am happy with bash, awk and sed, I have always avoided perl like the plague; I just can't stand the look of it (!) and can't be bothered amending my ways in that regard... If only python had been "invented" first!... :-)
Last edited by mcewanw on Mon 10 Sep 2007, 09:11, edited 1 time in total.

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

tried again afterall

#13 Post by mcewanw »

I was more awake and determined, so tried again afterall...

[all the following done on Puppy 2.17.1 with devx_217.sfs loaded]

This time I tried using CPAN.pm [thanks MU for tip], entering:

perl -MCPAN -e shell

then at cpan> prompt I entered: i Net::SSLeay
[that verified the module was available at CPAN]

Then I entered at cpan> prompt:
install Net:SSLeay

and cpan.pm started doing its business downloading everything. Alas, it ended with a similar error message as when I tried doing it all more manually with: ./Makefile.PL -t

With cpan.pm the error was:

[Begin error message]
System call "/usr/bin/wget -O - "ftp://ftp.perl.org/pub/CPAN/authors/id/ ... .32.tar.gz" > /root/.cpan/sources/authors/id/F/FL/FLORA/Net-SSLeay-1.32.tar"
returned status 1 (wstat 256)
Warning: expected file [/root/.cpan/sources/authors/id/F/FL/FLORA/Net-SSLeay-1.32.tar.gz] doesn't exist
No external ftp command available

Please check, if the URLs I found in your configuration file () are valid.
The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/'

Could not fetch authors/id/F/FL/FLORA/Net-SSLeay-1.32.tar.gz
Giving up on '/root/.cpan/sources/authors/id/F/FL/FLORA/Net-SSLeay-1.32.tar.gz'
[End error message]

Then I downloader the earlier 1.30.tar.gz of Net_SSLeay, and tried installing it with: ./Makefile.PL -t
but it gave the same kind of errors too.

I can't see that I'm doing anything wrong! What gives? If only I could get this bit working I'd be encouraged to keep going. Any thoughts?

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

Re: maybe tomorrow...

#14 Post by HairyWill »

mcewanw wrote:if my partner doesn't kill me for spending too much time with puppy linux recently....
You're not alone!!!
HairyWill wrote:
rarsa wrote:
Nathan F wrote:I've developed a habit of stopping every thirty secons or so just to make sure she isn't glaring at me.
I thought it was just me!
Ahh but by that time its too late.
http://www.murga-linux.com/puppy/viewto ... 907#102932
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

Re: maybe tomorrow...

#15 Post by mcewanw »

HairyWill wrote: You're not alone!!!
One can but laugh (or perhaps that should be weep) :-)

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

As for installing perl module Net::SSLeay on Puppy 2.17.1

#16 Post by mcewanw »

As for installing perl module Net::SSLeay on Puppy 2.17.1

In the readme provided in the tar.gz file it warns:

"You should use the same C compiler and options to compile OpenSSL, perl, and Net::SSLeay."

I'm pretty sure I'm doing everything right in trying to install the module (but I could be wrong...!), so I'm beginning to wonder if the version of perl in devx_217.sfs was compiled with a different C compiler than the one in there now? Seems unlikely, but I'm lost for ideas. I notice in the thread above that vovchik is using Puppy 2.10 not 2.17. I'd be grateful if anyone could find the time to simply try and install Net:SSLeay in Puppy 2.17.1 with devx_217.sfs loaded and let me know if they have the same problems (or not) that I do.

faulkmore
Posts: 3
Joined: Thu 06 Sep 2007, 07:06

As u have learned Perl isn't easy to use.

#17 Post by faulkmore »

taking some time to code TLS support into 'email'. I read the source code and i'm sure you can look at the smtp pear module for php http://pear.php.net/package/Net_SMTP and figure out from that code how to put TLS support into 'email'. Since i've hacked Net_SMTP and have read through the code for 'email' both are very very similiar. cough cough besides being written in different languages. Issue with PHP is it is super embarrasingly slow. Lets face facts, PHP isn't compiled and optimized like C. So speed wise 'email' is unlikely to disappoint.

So while we are at it:
* pipelining (batch) support (hint hint Net SMTP should think about adding this)
* The NET_SMTP code will use the best authentication method that the smtp server supports. With 'email' we are hard coding which auth method to use in a config file. So 'email' will fail if the smtp server does not support that auth method. A very avoidable situation. Use the best auth method silly and stop expecting end users to know what an auth method is.
* Japanese iso-2022-jp support plz. Both in the subject and body. Input text will be either shift_jis or utf-8. Not at all likely to be euc-jp. Net SMTP will never have this... Most PHP modules are lacking multi-byte language support and always will. It's embarrassing and shameful.
* multi-threading. Why be content with a pea shotter when we can have an out of control machine gun.

Perl yuk....Regular expressions yuk...only single byte encoding support yuk...puppy not supporting grub yuk...no way to say no ty thus bypass upgrading to a higher version of puppy yuk...

Kind Regards,
Dave Faulkmore

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

TLS support in email

#18 Post by mcewanw »

Good to hear you are working on implementing TLS support into email Dave.

Yes, Perl is a Pain, (though maybe I just wish I had taken the time to learn it years ago!), but its universality on Linux means it can't be ignored.

Hope you manage to code TLS into that other app, but in the meantime, since TLS is already available via perl for sendEmail, I would still like to know how to solve my problem installing Net::SSLeay. (I am pretty sure the problem is a minor one). That done, and I have the TLS support I need. So if anyone can try to install that perl module, please let me know how you got on. That would be a big help for me!

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

sendEmail installation problems

#19 Post by vovchik »

mcewanw:

I have experienced similar frustration in other contexts, so I can commiserate. However, I don't think you should give up entirely. My installation went relatively painlessly, once I had found the above-mentioned modules. I think I installed sockets::io first. I also did not use the "-t" switch; rather, I relied on pavlovian automatism with regard to perl module installation:

Code: Select all

perl ./Makefile.PL
make
make test
make install
Why don't you try installing without the "-t" switch and, if that fails, perhaps I can post the modules in question here.

regards,
vovchik

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

had tried that I'm afraid

#20 Post by mcewanw »

Had already tried it exactly as you say vovchik and even with the module versions you used. Tried installing in all combinations of order too. I think it is something to do with Puppy 2.17.1; I believe you used Puppy 2.10?
I'm using a clean install of 2.17.1 specially, and its no go.

Post Reply