#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Inida
    Posts
    2
    Rep Power
    0

    Question C code that follows SMTP protocol


    I need C sample code that follows SMTP Protocol to send an email in windows as well as Linux.
    Need some one to help me on this?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Bavaria, Germany
    Posts
    140
    Rep Power
    12
    Here's a sample SMTP session:

    telnet some.mail-server.com 25

    <- 220 some.mail-server.com ESMTP
    -> HELO from@from.org
    <- 250 some.mail-server.com
    -> MAIL FROM: from@from.org
    <- 250 some.mail-server.com ok
    -> RCPT TO: to@to.org
    <- 250 some.mail-server.com ok
    -> DATA
    <- 354 go ahead
    -> From: from@from.org
    -> To: to@to.org
    -> Subject: subject
    ->
    -> body
    -> .
    <- 250 some.mail-server.com ok some-id
    -> QUIT
    Now all you have to do is to write socket code which runs on windows and linux (which isn't hard at all, you just need to include
    different header files and initialize the winsock library
    on windows).

    And please don't bitch me about my c code, it has nearly no error handling, no buffer length checking, no mail server reply checking, ... but it works...sometimes ;-)
    Attached Files
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    12
    Swapna,

    Good luck. Windows and UNIX have very different approaches to the network. Under UNIX systems it is traditional to do a popen on mail or sendmail. A good example can be found at The Unix Programming Resources Page

    I don't know of any libraries for Windows that do this. Certainly they're available commercially. If you're in need of something capable of cross-compiling though I think you could be out of luck.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Inida
    Posts
    2
    Rep Power
    0

    smtp c code


    Hi Wingman,

    I compiled the file you sent in linux and executed it.

    But its giving the message as "Mail successfully sent."(for our local mail server),but at the other end we are unable to receive the mail.

    And while trying to send mails to few servers like yahoo.com,hotmail.com etc its giving error
    " failed to send mail with code -2"

    Thanks
    Swapna

IMN logo majestic logo threadwatch logo seochat tools logo