Logo Search packages:      
Sourcecode: nbsmtp version File versions  Download package

int nbsmtp_data ( servinfo_t serverinfo,
string_t msg 
)

Send the mail headers.

Parameters:
[in] serverinfo Pointer to a servinfo_t struct with the server information
[in] msg Pointer to the message
Returns:
1 in command success and -1 in case of error

Definition at line 130 of file nbsmtp.c.

References fd_puts(), log_msg(), nbsmtp_data_body(), nbsmtp_header(), smtp_last_message(), smtp_okay(), smtp_read(), smtp_write(), smtp_write_data(), and string::str.

Referenced by send_mail().

{
      char *local_out_buf;
      char local_in_buf[BUF_SIZE];
      char *msg_tmp;

      asprintf(&local_out_buf,"%s","DATA");

      if(smtp_write(serverinfo, local_out_buf)<1)
      {
            log_msg(LOG_ERR,"Error writting DATA command to the socket");
            return -1;
      }

      free(local_out_buf);

      /* Here the server should answer 354 so we check smtp_read to return '3' */
      if (smtp_read(serverinfo,local_in_buf)!=3)
      {
            log_msg(LOG_ERR,"An error ocurred after sending the DATA command");
            log_msg(LOG_ERR,"Server said: '%s'",smtp_last_message());

            return -1;
      }

      if (nbsmtp_header(serverinfo)<0)
      {
            return -1;
      }

      msg_tmp = (char *) strstr(msg->str, "\n\n");
      msg_tmp += 2;
      *msg_tmp = '\0';

      if ( smtp_write_data(serverinfo, msg->str, strlen(msg->str)) != 0 )
      {
            log_msg(LOG_ERR,"Error sending mail after DATA command");
            return -1;
      }

      if (nbsmtp_data_body(serverinfo)<1)
      {
            log_msg(LOG_ERR,"Error sending mail body");

            return -1;
      }

      asprintf(&local_out_buf,"\r\n.\r\n");

      if (fd_puts(serverinfo,local_out_buf,strlen(local_out_buf))<1)
      {
            return -1;
      }

      free(local_out_buf);

      /* Read last 221: Ok queued as... */
      if (!smtp_okay(serverinfo))
      {
            log_msg(LOG_ERR,"Error terminating data. Server said: '%s'.",smtp_last_message());
            return -1;
      }

      return 1;
}


Generated by  Doxygen 1.6.0   Back to index