The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   Send an email inside Terminal (http://hintsforums.macworld.com/showthread.php?t=81165)

dsd17 11-12-2007 02:44 PM

Send an email inside Terminal
 
Is there a way that I can create and send an email from within Terminal? Will I need to have postfix or anything turned on for this to work or can is there an option to define the smtp server?

son_t 11-12-2007 04:41 PM

Do you mean with a script? If so you can use Perl with the Net::SMTP module installed.

Do you mean interactively? If so you can use Pine (install the Fink application and use 'sudo apt-get install pine' would be the quickest...)

You will have to define an SMTP server in both method unless you have sendmail configured and running on your box...

trevor 11-12-2007 04:49 PM

You could certainly telnet into your smtp mail server and send email manually. Instructions are in many places on the 'net, hang on and I'll find one....

Here's one: Telnet - SMTP Commands (sending mail using telnet)

Others: Google search: telnet smtp

Trevor

P6SMSKC 11-12-2007 08:06 PM

Out of the box I could use,
Quote:

mailx notmyrealaddress@gmail.com < myfile.txt
and if I was online, the message would go right through, no configuration needed.

I was blown away.

Here's how I think it goes down, but be warned... I don't really know what I'm talking about... By default postfix is loaded as an on-demand service, so calling mail queues your message, and postfix directly contacts gmail (in this case) and attempts to deliver the message (no smtp config done here). I believe that this only works with certain servers (i.e. it works for me with gmail, but I just tested it with yahoo, and so far, no go).

Give it a try. If you want full functionality, you can set postfix to run as a daemon, and configure it to talk to your mail server (just don't ask me how yet...I'm still trying to learn).

acme.mail.order 11-12-2007 11:03 PM

Quote:

Originally Posted by son_t (Post 424230)
Do you mean with a script? If so you can use Perl with the Net::SMTP module installed.

Do you mean interactively? If so you can use Pine (install the Fink application and use 'sudo apt-get install pine' would be the quickest...)

You will have to define an SMTP server in both method unless you have sendmail configured and running on your box...

Quote:

Originally Posted by trevor (Post 424234)
You could certainly telnet into your smtp mail server and send email manually.

You guys really enjoy doing things the hard way. (manual session with SMTP? :eek: Easier to stuff a sheet of paper in an envelope. )

On many unix boxes since forever:

mail <address>

interactive and scriptable. with no address it reads your mail.

Wether mail sent in this (or any other local method) reaches it's destination depends on various intermediate providers and the recipient's spam filters.

ChrisA 11-12-2007 11:17 PM

Quote:

Originally Posted by dsd17 (Post 424190)
Is there a way that I can create and send an email from within Terminal? Will I need to have postfix or anything turned on for this to work or can is there an option to define the smtp server?

There must be 50 ways you can do this

The most basic command for doing this is "mail".
Use "cat" to pipe your message to mail
See man mail. If you do have postfix or sendmail running on the local computer then you can queue the outgoing mail do retries and rewrites and a ton of stuff. "mail" works well inside a script

You can also use the "sendmail" command inside a script

You can also use telnet to port 25 and type the SMTP protocol directly. Very primitive but a reasonable way to debug a setup

for interactive use at the terminal "mail" works but is primitive. Pine and elm are both better

acme.mail.order 11-12-2007 11:22 PM

Quote:

Originally Posted by ChrisA (Post 424347)
for interactive use at the terminal "mail" works but is primitive. Pine and elm are both better

I agree that there are better things than `mail` for the job, but mail is present on a lot more systems than pine. Most unix webhosts, for example, don't allow users to install system software.

trevor 11-13-2007 12:01 AM

Quote:

Originally Posted by acme.mail.order (Post 424339)
You guys really enjoy doing things the hard way. (manual session with SMTP? :eek: Easier to stuff a sheet of paper in an envelope. )

The only case where I would ever want to send an e-mail from the command line would be to troubleshoot an SMTP server issue. Otherwise, the GUI is far superior for sending and receiving e-mail. And to troubleshoot an SMTP server issue, a manual telnet session gives you the best feedback.

Whereas I have run into several instances where I prefer (or must use) a command-line web browser, there have never been any where I would prefer a command-line mail client. I used a unix command line e-mail client in 1985/86 for all of my e-mail, and that's recent enough for me.

Trevor

P6SMSKC 11-13-2007 12:19 AM

Quote:

Originally Posted by trevor (Post 424370)
The only case where I would ever want to send an e-mail from the command line would be to troubleshoot an SMTP server issue. <big snip>

I have a script which uuencodes an excel spreadsheet, and emails it to a gmail account periodically. very handy. I'm sure this is doable in applescript or probably even automator, but I'm learning more unix this way and that can't be bad.

son_t 11-13-2007 06:04 AM

Quote:

Originally Posted by acme.mail.order (Post 424339)
You guys really enjoy doing things the hard way. (manual session with SMTP? :eek: Easier to stuff a sheet of paper in an envelope. )

On many unix boxes since forever:

mail <address>

interactive and scriptable. with no address it reads your mail.

Wether mail sent in this (or any other local method) reaches it's destination depends on various intermediate providers and the recipient's spam filters.

It is simple your way because you have a mail agent configured on your box. I assumed that the OP is an average user (i.e. Mac OS X) and only has his mail client application set up.

My way is a lot easier than having to setup your own mail server - which is what is running on your OS X box if you can simply use 'mail' to send emails!!!

You are having a laugh if you think mail or mailx would just simply work with 'OS X out of the box'!

P6SMSKC 11-13-2007 07:31 AM

Quote:

You are having a laugh if you think mail or mailx would just simply work with 'OS X out of the box'!
Havin' a laugh then...'cause it did for me.

acme.mail.order 11-13-2007 07:57 AM

Quote:

Originally Posted by son_t (Post 424442)
It is simple your way because you have a mail agent configured on your box. ...
You are having a laugh if you think mail or mailx would just simply work with 'OS X out of the box'!

I don't remember ever setting up a mail server.

son_t 11-13-2007 08:02 AM

Quote:

Originally Posted by P6SMSKC (Post 424447)
Havin' a laugh then...'cause it did for me.

OK, taking your post seriously ;) I investigated...

Quote:

Originally Posted by acme.mail.order (Post 424455)
I don't remember ever setting up a mail server.

Looks like if you setup the Mail application with the correct details then the mail Unix program does work as described above. (Where else would the system get info like smtp server and your mailserver? And please tell me you did setup the Mail app!?)

I use Thunderbird as the mail application so settings never get inherited down to the system level (as I am assuming this is what is happening here).

Sorry for the doubts :)

son_t 11-13-2007 08:26 AM

Another experiment... just tried mail on another box WITHOUT the Mail app configured... it works! So I am :confused:

It has never worked before because I never used the FQDN and just my username...

So I conclude from this experiment that the Unix mail program can get its information from ANY mail client... unless someone can correct me here ;) (Where is the smtp server info held?)

dsd17 11-13-2007 08:59 AM

Quote:

Originally Posted by trevor (Post 424370)
The only case where I would ever want to send an e-mail from the command line would be to troubleshoot an SMTP server issue. Otherwise, the GUI is far superior for sending and receiving e-mail. And to troubleshoot an SMTP server issue, a manual telnet session gives you the best feedback.

Trevor

This is exactly what I am wanting to do. We have about 20 websites/email accounts that we deal with and we wanted to automate sending out test emails. Figured I could either go this way or create an automator/applescript job and have it executed with a cronjob.

son_t 11-13-2007 09:29 AM

I did some further investigation... and tests...

The mail agent on OS X is postfix: http://www.postfix.org/start.html

It seems quite smart and needs no configuration! It uses some kind of DNS lookup mechanism to find the MX hosts of the domain you are sending an email to. So if I send an internal email with my FQDN in the email address, then my box would talk to my site's MX hosts and get the message delivered.

I have tried to email to external accounts and no email has appear yet! I suspect my local box is talking (or trying to resolve) the MX hosts for these email addresses... and not getting permission to talk to the hosts directly...

This could be considered clever or dangerous. Imagine if your Mac got compromised and some spammer floods your site with messages - potential taking your MX hosts down...

mattipoo 11-13-2007 02:35 PM

email
 
hey im logged in as root in the terminal id to know how to send email from someone else is email address to lets say mine for instance lets say i dont know that person's password, i used to know about this i forgot,anybody gotta any idea?

thanks

Craig R. Arko 11-13-2007 04:44 PM

Quote:

Originally Posted by mattipoo (Post 424595)
hey im logged in as root in the terminal id to know how to send email from someone else is email address to lets say mine for instance lets say i dont know that person's password, i used to know about this i forgot,anybody gotta any idea?

thanks

I'd suggest asking them. ;)

Lutin 11-13-2007 06:29 PM

Quote:

Originally Posted by mattipoo (Post 424595)
hey im logged in as root

The kind of message you usually get when you run sudo for the first time:

"We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility."

I think you should log out. :o

Straitsfan 07-24-2009 06:37 PM

Guys, I'm trying to learn about this as well, but can't figure out the man page. Could someone walk me through the steps needed to create and send a mail message to an address on the internet (say to someone else) from the Terminal?

acme.mail.order 07-25-2009 01:44 AM

Type:

mail person@example.com

and follow the prompts. type
.

all by itself to finish.
Wether the recipient gets the message depends a lot on your ISP's outgoing mail policies.

Straitsfan 07-25-2009 07:53 AM

I just tried sending a message to my own gmail account. I typed my email address, pressed return, and got the subject line, entered 'test' as subject, pressed return, and entered some more text, then pressed return again, then the . it said "EOT" and the terminal prompt. But there's nothing inside my gmail inbox.

Do I have to configure something else? And why is it so complicated? The book I have doesn't explain this. Are there any other books on UNIX that I could get/you recommend? I'm currently reading "Learning the bash shell' by Newham & Rosenblatt, published by O'Reilly.

acme.mail.order 07-25-2009 08:03 AM

The last sentence of my previous post is your answer. Many ISPs block mail servers other than their own, preventing bot-spam but also preventing you sending out mail.

On the other end, receiving mail servers sometimes block mail from servers that don't have a vaild reverse DNS record (your home machine will definitely not have a valid record).

I can't send mail from my home machine either, but I can from my web provider's machine, same command.

baf 07-25-2009 08:11 AM

see this hint it configures postfix to send mail via your isp and should work.

honestpuck 07-27-2009 07:18 PM

Straitsfan,

Well if you type "man mail" at the command prompt you'll get a nice summary.

mail -s "I'm sending you a letter" someone@example.com < letter.txt

That line tells you most of what you need to know.

You run the mail command supplying it a subject and the address you want the letter to go to and then redirect in the text.

// Tony


All times are GMT -5. The time now is 10:17 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.