Solved

send mail using sockets

Posted on 2004-09-14
15
237 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 61

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 61

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

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

The DSL Parameters part of this article is valid and can be considered with any brand of internet router and modem (Dlink, 3com, Alcatel, Usrobotics, Parks), by accessing the configuration interface available by the manufacturer eg: http://10.1.1.1 …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

17 Experts available now in Live!

Get 1:1 Help Now