Hi !
How to send an email to an emailadress on the internet, ex info@company.com by using the Mail program in Bash ?
Is there some configuration to do before ?
Hi !
How to send an email to an emailadress on the internet, ex info@company.com by using the Mail program in Bash ?
Is there some configuration to do before ?
mail you@somewhere.com
CTRL D to send
Registered Linux User: #376813
Western NY
My linux site
Smolt Profile
please remember to say if you problem was solved
Did you get your id10t award today?
Hi, a simple use of mail is as follows:
where -s specifies the subject. Prepare your message (msg.txt) as follows:Code:& mail -s 'Subject' info@company.com < msg.txt
Send a message to your self and try :o)Code:From: your.address@foo.com To: info@company.com (mandatory) Subject: (optional) Cc: (optional) Bcc: (optional) Your message
Best wishes, SRS
would also work in a bash script.Code:mail -s 'Subject' info@company.com < msg.txt
What have I missed ?Code:[MrTux@localhost ~]$ /home/MrTux/dead.letter... Saved message in /home/MrTux/dead.letter
I want to send to the Internetemailadress but i only get a 'dead.letter'
I have sendmail installed but is there something to do with that before its working ?
The problem with the standard 'mail' command is that it assumes that the machine it is running on is a full-fledged SMTP server. So unless you've configured your machine to be a bonafide mail server (or to act as an SMTP relay), then your mail will not go anywhere outside your machine (i.e. it will only work for addresses local to your machine, e.g. some_user@localhost). There is no way to specify an external SMTP server (like your ISP's) to use with the 'mail' command. That's why you're getting a dead letter.
If you want a command-line mailer that does support using an external SMTP server, then get nail from Fedora Extras. Nail supports specifying an external SMTP server. You can do this on a per-mail basis, like this:
nail -r "myaddress@something.com" -s "Some subject" -S smtp=some.smtp.server info@company.com < msg.txt
or you can permanently set the SMTP server in your ~/.mailrc file (or /etc/nail.rc if you want to set it system-wide), which removes the need for using the "-S smtp=..." option on the command-line:
set smtp=some.smtp.server
See the nail man page for more details. In my opinion, no one should be using 'mail' anymore, nail is vastly superior.![]()
For simple mails, an alternative is to use Python. nail is better than my very simple Python script put together before bed time, though :o)
Best wishes, SRSCode:#!/usr/bin/env python # Usage: ./mail.py import sys import smtplib def prompt(prompt): return raw_input(prompt).strip() def create_message(): fromaddr = prompt('From: ') toaddrs = prompt('To: ').split() subject = prompt('Subject: ') print 'Enter message, end with ^D (Unix) or ^Z (Windows): ' msg = ('From: %s\r\nTo: %s\r\nSubject: %s\r\n\n' \ % (fromaddr, ', '.join(toaddrs), subject)) while 1: try: line = sys.stdin.readline() except EOFError: break if not line: break msg = msg + line return fromaddr, toaddrs, msg def send_mail(fromaddr, toaddrs, msg): server = smtplib.SMTP('localhost') server.sendmail(fromaddr, toaddrs, msg) server.quit() def main(): [fromaddr, toaddrs, msg] = create_message() send_mail(fromaddr, toaddrs, msg) if __name__ == '__main__': main()
Well, nail has a lot of options, like the ability to send attachments easily, so I'd agree that nail is better.Originally Posted by srs
![]()
Thanks alot for the information.
I skip Mail then and install nail instead.
Update info from Internet:
As of March 2006, nail has been integrated into the Heirloom project as mailx.
http://heirloom.sourceforge.net/mailx.html
Thanx
Mr Tux
Last edited by Mr Tux; 7th January 2007 at 02:07 PM.
In Fedora 13 the old mail command has been replaced by nail, which is now called Mailx, and /bin/mail is just a link to /bin/mailx. So now mail works as users expect it to.