?
Solved

Send mail from console, specify server to use

Posted on 2005-03-15
13
Medium Priority
?
3,626 Views
Last Modified: 2011-10-03
I'm wanting to use the mail command to send an email, but I'm not sure how to specify which server for it to try and use... I need to be able to specify which mailserver to send the message to first.

Thanks,

Paul.
0
Comment
Question by:H4Inf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 26

Expert Comment

by:jar3817
ID: 13550755
You can't do that with the mail command.  It uses dns mx records to decide what server to send email to. Any particular reason why you want to send this msg to some intermediate relay server?
0
 

Author Comment

by:H4Inf
ID: 13550781
Can I do it with mutt?

Basically our workplace has 2 internet connections. If the one that this machine routes through goes down, I want it to send an email through a server which routes through the other connection.
0
 
LVL 9

Assisted Solution

by:e-tsik
e-tsik earned 800 total points
ID: 13552267
Hi :-)

1. Put this in .muttrc
set sendmail="/usr/sbin/sendmail -oem -oi -O SMART_HOST=my.relay.host.com

In case you would like to change, either edit that .muttrc to have a different relay host or (a bit less stable create an entry on /etc/hosts that has a different IP address).

2. You can use this example to send mail directly
sendmail your-recipient@domain.com -O SMART_HOST=my.relay.host.com

(You will get an empty response waiting for you to write you entire email, including headers)
From: me@mydomain.com
Subject: TEST!

Test
<CTRL-D>

Notice that empty line between the headers and the message body.


The above works with sendmail. If you use postfix or qmail, that requires specific parameters to be entered to each daemon.
0
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 

Author Comment

by:H4Inf
ID: 13552732
I'll be doing this from a script, so is there a neat way to pipe the data into mutt, and setup the to and subject fields in the command line?

Cheers!
0
 
LVL 9

Assisted Solution

by:e-tsik
e-tsik earned 800 total points
ID: 13552843
Taken from the man page

       -e command
              Specify a configuration command to be run after processing of initialization files.

mutt -e 'set sendmail="/usr/sbin/sendmail -oem -oi -O SMART_HOST=my.relay.host.com"'

That should work
0
 
LVL 8

Expert Comment

by:marxy
ID: 13552981
That's too easy.
Just do

cat  x| mail -s Test marxy@hotmail.com

The simpliest way of mail is to specify -s (subject) parameter and mail address.
0
 

Author Comment

by:H4Inf
ID: 13553029
Marxy you missed the point... To send through a specified mail server...

I will give that a go on friday e-tsik, thanks for your help :-)

Paul.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 1200 total points
ID: 13559712
cat  <<EoM| telnet name-or-IP-of-mailserver 25
helo yourserver
mail from: you@here.tld
rcpt to: you@somewhere.else
data
Subject: your subject

body goes here
.
EoM

# should work on any UNIX/linux ;-)
0
 

Author Comment

by:H4Inf
ID: 13649829
e-tsik, sendmail doesn't like the -O option... I actually use qmail on this system.. maybe that is why.

ahoffmann... Can't seem to get that to work properly...

mail root # ./newfile
Trying 192.168.0.7...
Connected to 192.168.0.7.
Escape character is '^]'.
Connection closed by foreign host.


mail root # cat newfile
#!/bin/sh
cat <<EoM| telnet 192.168.0.7 25
helo 192.168.0.7
mail from: from@domain
rcpt to: to@domain
data
subject: the subject
body goes here
.
EoM

Cheers,

Paul.
0
 
LVL 2

Expert Comment

by:kutashi
ID: 14062613
you could always just use telnet, and connect to a mail server on port 25, and then just manually type in the commands like that
0
 

Author Comment

by:H4Inf
ID: 14064325
Manually typing is not an option, it needs to send automatically when the connection goes down... I can do the logic behind that, just need a way of specifying outgoing server in order to send through a connection that's working.
0
 

Author Comment

by:H4Inf
ID: 14657595
So any more ideas. . . ? Surely theres a program out there which allows you to specify which mailserver you want to send through.. in console, from a script.
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question