Help needed for C++ SMTP Client

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sighsighsigh
    New Member
    • Feb 2008
    • 1

    Help needed for C++ SMTP Client

    Hi, may i know how do i take in user inputs and set them for "Subject", "To" and "From"?
    ===
    my code:
    write(sockfd,"D ATA\r\n",strlen ("DATA\r\n") );
    strcpy (msgToSvr, "");
    cin.getline(bod y, 99, '\n');
    strcat (msgToSvr, subject);
    strcat (msgToSvr, "\r\n");
    write(sockfd,ms gToSvr,strlen(m sgToSvr));
    strcpy (msgToSvr, "");
    cin.getline(bod y, 99, '\n');
    strcat (msgToSvr, from);
    strcat (msgToSvr, "\r\n");
    write(sockfd,ms gToSvr,strlen(m sgToSvr));
    strcpy (msgToSvr, "");
    cin.getline(bod y, 99, '\n');
    strcat (msgToSvr, to);
    strcat (msgToSvr, "\r\n");
    write(sockfd,ms gToSvr,strlen(m sgToSvr));
    write(sockfd,"\ r\n",strlen("\r \n"));

    ===

    char subject[100], from[100], to[100] are all input from user.

    however when i check my mail.. the subject, from, and to are in my message body. They should not be in the body..

    right now i'm getting
    ===
    Subject: Hello
    From: John
    To: Peter
    ===

    in the body.

    how do i get the user inputs and assign them to the proper places?
  • Arulmurugan
    New Member
    • Jan 2008
    • 90

    #2
    Originally posted by sighsighsigh
    Hi, may i know how do i take in user inputs and set them for "Subject", "To" and "From"?
    ===
    my code:
    write(sockfd,"D ATA\r\n",strlen ("DATA\r\n") );
    strcpy (msgToSvr, "");
    cin.getline(bod y, 99, '\n');
    strcat (msgToSvr, subject);
    strcat (msgToSvr, "\r\n");
    write(sockfd,ms gToSvr,strlen(m sgToSvr));
    strcpy (msgToSvr, "");
    cin.getline(bod y, 99, '\n');
    strcat (msgToSvr, from);
    strcat (msgToSvr, "\r\n");
    write(sockfd,ms gToSvr,strlen(m sgToSvr));
    strcpy (msgToSvr, "");
    cin.getline(bod y, 99, '\n');
    strcat (msgToSvr, to);
    strcat (msgToSvr, "\r\n");
    write(sockfd,ms gToSvr,strlen(m sgToSvr));
    write(sockfd,"\ r\n",strlen("\r \n"));

    ===

    char subject[100], from[100], to[100] are all input from user.

    however when i check my mail.. the subject, from, and to are in my message body. They should not be in the body..

    right now i'm getting
    ===
    Subject: Hello
    From: John
    To: Peter
    ===

    in the body.

    how do i get the user inputs and assign them to the proper places?

    you need to communicate with SMTP server as follows

    helo "server name"
    mail from: <mailid>
    recpt to: <mailid1>
    rcpt to: <maild2>
    data
    subjact: subject line

    body message
    . <------- must

    all lines even empty line has to endup with \n\r.
    Regards,
    Arul

    Comment

    Working...