Operating System - HP-UX
1834185 Members
2752 Online
110064 Solutions
New Discussion

Send an email by SMTP from a file

 
Antonio Iram
Occasional Contributor

Send an email by SMTP from a file

I need send a mail by SMTP from a file, The commands and information that I need send is into this file.
When I send the mail I do in this way.
telnet 25 < My_file
But this instruction cause many errors.
My_file:
HELO atl.hp.com
MAIL FROM:
RCPT TO:
DATA
To: "My friend"
Subject: Test

I need send this mail.
I expected that all is rigth
Bye

.
quit

7 REPLIES 7
Steven E. Protter
Exalted Contributor

Re: Send an email by SMTP from a file

I will show you a scripting concept that will let you do this:

telnet $hostname 25 << EOF
HELO atl.hp.com
MAIL FROM:
RCPT TO:
DATA
To: "My friend"
Subject: Test

I need send this mail.
I expected that all is rigth
Bye
..
EOF

This kind of script could obviously be modifed and used to relay spam through a smtp server with light security.

That would be a very bad idea. Plus illegal in all 50 states now.

I've spent some time learning how to defeat such scripting and can configure any sendmail server to do it.

I'm sure your purpose is good and apologize if I've gone over the line here.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Antonio Iram
Occasional Contributor

Re: Send an email by SMTP from a file

Thank you but I had already tried to do this and it didn't work.
I forgot to mention that I want to send several mail messages from a HP9000 over UNIX, using shells and that I have created an unique file with information for some of my clients that requested it.
But in both ways, executing the script or using a text file like entry, the server sends me error messages until they are so many that the execution is interrupted in both ways.
Using the script like a shell or using the command:
"TELNET HOSTNAME 25 << EOF
Where My_file contains the following lines:

HELO My_domain
MAIL FROM:
RCPT TO:
DATA
To: "My friend"
Subject: Test

I need send this mail.
I expected that all is rigth
Bye
.
EOF

Apparently a way exists to send the mails using SMTP and SFF (Send From File),
But I don't know how to do it.
Can you help me?
Nicolas Dumeige
Esteemed Contributor

Re: Send an email by SMTP from a file

Does your script work ?
This kind of stuff normaly doesn't work properly, if you need to emulate a connection use expect.
Anyway, why not use somthing like this :
cat $FILE | mailx -s "Subject" name@domain.com

My 2 cents (of euro :)
All different, all Unix
Elmar P. Kolkman
Honored Contributor

Re: Send an email by SMTP from a file

I think Nicholas has a point. Why not let your sendmail daemon resolv the problems... Unless you want to spoof the user sending the mail, that should solve the issue. In your mail log files a lot more info can be found why mail is rejected.

What is the error message you get? You might try out a telnet to the other server's port 25 to see if there is a sendmail listening. Perhaps your problem is with that. If not, it might be the sendmail config rejects your mail because sendmail is configured by someone like SEP... For instance, you do a HELO atl.hp.com, but there is no link between atl.hp.com and your IP address...
By doing the stuff you try by hand, you get a better view of error messages.

It might also help if you could take a look at the maildaemon log on the machines you're trying to connect to.
Every problem has at least one solution. Only some solutions are harder to find.
Paddy_1
Valued Contributor

Re: Send an email by SMTP from a file

I may not be answering your question directly but I was wondering if the option of sending the file as an attachment is valid.

If thats the case you could use uuencode as said in the following thread :
http://forums1.itrc.hp.com/service/forums/questionanswer.do?admit=716493758+1079705834401+28353475&threadId=7923

The sufficiency of my merit is to know that my merit is NOT sufficient
David Burgess
Esteemed Contributor

Re: Send an email by SMTP from a file

Using mailx and mail to send emails :-

#mailx -s "Subject here" user@domain.com < filename

#echo "This is the body text" | mailx -s "Subject here" user@domain.com

#cat filename | mailx -s "Subject here" user@domain.com

This one uses mail rather than mailx and allows you include the subject in the echo statement which gives you more control.

#echo "Subject: test\nbody text" | mail user@domain.com

Regards,

Dave.
John Flanagan
Regular Advisor

Re: Send an email by SMTP from a file

try

cat filename | uuencode filename | mail username@domain

if you want the file in dos format
cat filename | ux2dos filename | uuencode filename | mail username@domain

Regards,

John.