Hi all, Is it possible to send mail from CLI (bash, python) without any LOCAL SMTP installed, using SMTP on another machine. Care to give a glimpse of the code? Thank you.
On Thu, Apr 01, 2010 at 12:04:10PM +0800, Fajar Priyanto wrote:> Hi all, > Is it possible to send mail from CLI (bash, python) without any LOCAL > SMTP installed, using SMTP on another machine. > Care to give a glimpse of the code? > Thank you.http://www.lmgtfy.com/?q=send+email+via+python ;-) Ray
On Thu, 1 Apr 2010, Fajar Priyanto wrote:> Is it possible to send mail from CLI (bash, python) without any LOCAL > SMTP installed, using SMTP on another machine. > Care to give a glimpse of the code?One approach step 1: make sure packages 'expect' and 'telnet' are installed step 2: read: man autoexpect and RFC 2821 ... see worked example for handing email to a remote server http://www.owlriver.com/tips/sendmail-tip/ http://www.owlriver.com/tips/trace-sendmail/ step 3: experiment to taste in talking the protocol. 'expect' and autoexpect makes it trivial to build a script that works -- Russ herrold
Joseph L. Casale
2010-Apr-01 04:55 UTC
[CentOS] Sending mail from CLI to another SMTP host
>Hi all, >Is it possible to send mail from CLI (bash, python) without any LOCAL >SMTP installed, using SMTP on another machine. >Care to give a glimpse of the code? >Thank you.But of course, just cause the smtp server you are pointed at initially is local, interpret that as 127.0.0.1. So point to another. Most home users don't have their own smtp server, they use their isp's... http://heirloom.sourceforge.net/mailx.html "Supports SMTP to send messages directly to a remote server. A local sendmail interface setup is thus not necessary."
On Thu, 2010-04-01 at 12:04 +0800, Fajar Priyanto wrote:> Hi all, > Is it possible to send mail from CLI (bash, python) without any LOCAL > SMTP installed, using SMTP on another machine.I use this: http://www.cleancode.org/projects/email -- MELVILLE THEATRE ~ Melville Sask ~ http://www.melvilletheatre.com
Fajar Priyanto wrote:> Hi all, > Is it possible to send mail from CLI (bash, python) without any LOCAL > SMTP installed, using SMTP on another machine. > Care to give a glimpse of the code? > Thank you.Personally, I'd use the default Centos install of sendmail because it's there, it's easy, and it works the way mail has been intended to work for decades. The default setup is to accept only from localhost, but send anywhere. If you want to relay through a known host, configure SMART_HOST in /etc/mail/sendmail.mc and restart the sendmail service. Then your scripts and other programs can simply run sendmail to queue/delivey instead of doing it themselves, and can deliver to local recipients as well as remote. If you really don't want a mailer and are ok with failures or want to handle queuing and retries yourself, the epel repo has perl-Mail-Sender which is a fairly complete smtp send-only client. After installing use perldoc or 'man Mail::Sender' to see the documentation. -- Les Mikesell lesmikesell at gmail.com
Jobst Schmalenbach
2010-Apr-06 03:22 UTC
[CentOS] Sending mail from CLI to another SMTP host
install perl, Net::SMTP, MIME::Lite and Email::Valid and read the manuals which give very simple examples on how to do it e.g. man Net::SMTP jobst On Thu, Apr 01, 2010 at 12:04:10PM +0800, Fajar Priyanto (fajarpri at arinet.org) wrote:> Hi all, > Is it possible to send mail from CLI (bash, python) without any LOCAL > SMTP installed, using SMTP on another machine. > Care to give a glimpse of the code? > Thank you. > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos-- C is a write-only language. | |0| | Jobst Schmalenbach, jobst at barrett.com.au, General Manager | | |0| Barrett Consulting Group P/L & The Meditation Room P/L |0|0|0| +61 3 9532 7677, POBox 277, Caulfield South, 3162, Australia
On Wed, Mar 31, 2010 at 9:04 PM, Fajar Priyanto <fajarpri at arinet.org> wrote:> Hi all, > Is it possible to send mail from CLI (bash, python) without any LOCAL > SMTP installed, using SMTP on another machine. > Care to give a glimpse of the code? > Thank you. > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >The enclosed script works for python 2.5 (it's an example.) If you don't use the localhost sendmail, then you'll have to relay through another sendmail server - and good luck with that. Maybe you can relay through a Google? ;----------------------------------------------------------; #!/usr/bin/env python import smtplib def prompt(prompt): return raw_input(prompt).strip() fromaddr = prompt("From: ") toaddrs = prompt("To: ").split() print "Enter message, end with ^D (Unix) or ^Z (Windows):" # Add the From: and To: headers at the start! msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddr, ", ".join(toaddrs))) while 1: try: line = raw_input() except EOFError: break if not line: break msg = msg + line print "Message length is " + repr(len(msg)) server = smtplib.SMTP('localhost') server.set_debuglevel(1) server.sendmail(fromaddr, toaddrs, msg) server.quit() -- Enjoy global warming while it lasts.