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
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
http://www.rdpslides.com/webresources/FAQ00035.htm
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.
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@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@centos.org http://lists.centos.org/mailman/listinfo/centos
On Wed, Mar 31, 2010 at 9:04 PM, Fajar Priyanto fajarpri@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@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()
On Mon, 2010-04-05 at 23:18 -0700, Agile Aspect wrote:
On Wed, Mar 31, 2010 at 9:04 PM, Fajar Priyanto fajarpri@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@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()
why not just 'export smtp=someserver.com:25' and then using 'mail' command?
Calin
Key fingerprint = 37B8 0DA5 9B2A 8554 FB2B 4145 5DC1 15DD A3EF E857
================================================= We have more to fear from the bungling of the incompetent than from the machinations of the wicked.