Solved

manual smtp session is not working anymore

Posted on 2008-09-30
6
515 Views
Last Modified: 2013-12-26
Hi experts

I make my bash scripts send mail through a simple "mail.sh" script (see attached code snippet).

But for a few days, I cannot send anymore this way. I tried an smtp session manually, and apparently the problem is that the end of the message is not recognised.

Yet I enter a dot on a line by itself just as the smtp server says to do  ("Enter mail, end with "." on a line by itself").

And it used to work beautifully.

Any idea what I add to my script to make the smtp server recognize the end of DATA ?

thanks a lot


PS : I do not have control over the smtp server
#! /bin/sh 

nc mymailserver.com 25 << FIN

EHLO mymailserver.com

auth plain aaaa_MYBASE64PASSWORD___aaa

MAIL FROM: sender@mymailserver.com 

RCPT TO: $1 

DATA 

Subject: $2

$3
 

.

quit

FIN

Open in new window

0
Comment
Question by:Michaelhv
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Expert Comment

by:chris_barry
Comment Utility
I'm afraid I can't see what is wrong with your script, but have you considered using blat?
0
 
LVL 1

Expert Comment

by:chris_barry
Comment Utility
Sorry, I thought that blat was a Linux utility which had been ported to Windows. I see now that it is Windows only.

What I should have said was consider using sendmail.
0
 
LVL 3

Accepted Solution

by:
alien_life_form earned 500 total points
Comment Utility
As for the script, I think you may be having a <LF><CR> problem (in that the receiving server insists on a final <CR>, that the BASH script is not sending. (qmail poses this kind of problems... of course qmail POV is that it is doing the right thing.)


You may want to either:
i) Rewrite in a different language (e.g. perl) usinf a mail library
ii) use a system command, either mail or sendmail would do the trick.

Cheers,
alf
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Michaelhv
Comment Utility
hello ; thanks for the comment, but I'd like to stick with the bash script. Is there a way I can make it send a <LF><CR> ?
0
 
LVL 3

Expert Comment

by:alien_life_form
Comment Utility
Not that I know of, not with nc.

But please note that using (for example) sendmail involves nothing more than replacing "nc mymailserver.com 25" with "sendmail -bm", and a properly configured local sendmail (or moral equivalent). You'd still be sticking with the shell script.

Cheers,
alf
0
 

Author Comment

by:Michaelhv
Comment Utility
hello

I found the solution : thanks to your input, I understood it was a problem with crlf. So I did a text file with
crlf
.
crlf

, and in my script I added the line mycrlf=`cat mycrlffile.txt`

I used the utility http://ccrma-www.stanford.edu/~craig/utility/flip/ to make sure my crlfile.txt file used crlf line endings (dos-style).

thanks !
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now