Solved

send mail using sockets

Posted on 2004-09-14
15
242 Views
Last Modified: 2013-12-23
I have a  program in C which uses unix sockets to send mail from server to microsoft exchange client. The mail are sent using the email relay.

If i try HELO.., MAIL FROM.. (manually), it works fine, but when i try the same using the program i get the error 'Timeout occured for client' .

The C program establishes connection and sends data in the order of

1. HELO
2. MAIL FROM: <from emailid>\n
3. RCPT TO: <to emailid>\n
4. DATA ..
..
QUIT

After each step there is a read command to check if the earlier command has completed without errors. My problem is that, the program hangs after step 2 and i get error "451 Timeout waiting for client input" after about 10 minutes.
0
Comment
Question by:kcube
  • 6
  • 4
  • 2
15 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12063192
> ..  from server to microsoft exchange client
what exactly is a "microsoft exchange client"?

i.g. you cannot send to a client (MUA) just to a server (MTA). Or did you just use the wrong words?
0
 

Author Comment

by:kcube
ID: 12073282
Iam sorry for the wrong use of words. It should have been communicating to a microsoft exchange server not client. The C program is on a solaris box and it initiates a connection with the microsoft exchange server.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 250 total points
ID: 12073379
if exchange operates in a RFC-compliant mode (HELO, MAIL FROM, RCPT TO, etc.) then it should work, you can simply test with:
   telnet exchange-hostname 25
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:kcube
ID: 12074345
Yes, i have already tried telnet exchange-hostname 25.
The command works fine and iam able to send mails.  

But when i try the same using the program, it does not work. The program establishes a connection to the exchange server and sends the data, but hangs after sending MAIL FROM: value. I am using socket write and read to send the values and receive the output from the exchange server. The write works fine till the MAIL FROM: is sent, but the read command after it hangs. This is the extract from the code which is causing the problem.

..
        sprintf(buf, "HELO\r\n");
        write(fd, buf, strlen(buf));
        read(fd, buf, 256);

        sprintf(buf, "MAIL FROM: <%s>\n", from);
        write(fd, buf, strlen(buf));
        read(fd, buf, 256); /* hangs here */
..

any clues?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12076249
>    read(fd, buf, 256);

and you're 300% shure that Exchange does not send more than 256 bytes?
0
 

Author Comment

by:kcube
ID: 12077088
I believe the message would be truncated to 256 bytes. Iam only checking the first 3 chars to see if its 250  ... signifying that no errors have occured
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12078621
and what does exchange do when it cannot deliver 257 bytes? do you know?
I assume that it closes the connection.
0
 

Author Comment

by:kcube
ID: 12082597
Thanks for your replies. To find the size of data being received, i have tried to use MSG_PEEK in a 'recv' command and checking the return value, instead of 'read'. This also hangs. If i comment out all the read commands, then the program runs through but no email is relayed by exchange server. How can i check the size of data being received in this situation. I have also tried changing the size from 256 to 2048 which is the size of 'buf' variable, but to no avail. Also, is there any way i can get around the size issue.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12082648
sounds like M$ implemented standards their own way again :-((
Sorry I don't know anything about M$ and its programming, I'd use a tcp/ip sniffer and watch what happens with telnet and then with your programm. The difference in the protocol handshake should point to the problem.
0
 
LVL 62

Expert Comment

by:gheist
ID: 12187922
Basically HELO must have an argument, good exchange tracks standards well
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12468013
basicaly HELO must not have an argument
I'd vote for PAQ norefund
0
 
LVL 62

Assisted Solution

by:gheist
gheist earned 250 total points
ID: 12491821
RFC821 3.3 OPENING AND CLOSING
RFC2821 4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO)


maybe you stick to some strong intranet standards which do not apply anywhere else.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Load balancing - basic design/questions for customer request 4 61
EIGRP STUB 19 69
Dns issues 4 34
move My Documents folder location to point to server's my documents 4 25
Data center, now-a-days, is referred as the home of all the advanced technologies. In-fact, most of the businesses are now establishing their entire organizational structure around the IT capabilities.
Most of the applications these days are on Cloud. Cloud is ubiquitous with many service providers in the market. Since it has many benefits such as cost reduction, software updates, remote access, disaster recovery and much more.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

816 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

7 Experts available now in Live!

Get 1:1 Help Now