I managed to create the fields by slightly modifying your sendmail function:
void sendmail() { write_command("MAIL FROM: < foo@bar.de >"); write_command("RCPT TO: < foo@bar.de >"); write_command("DATA"); std::string data; data.append("MIME-Version: 1.0\r\n"); data.append("From: < foo@bar.de >\r\n"); data.append("To: < foo@bar.de >\r\n"); data.append("Subject: Welcome\r\n"); data.append("Date: Fri, 29 Dec 2017 09:30:00 -0400\r\n"); data.append("\r\n");
I put all the DATA in a string and sent it to one record.
What (apparently) matters:
- Do not start the data section with an empty string;
- add a blank line before the message body.
I also edited your write_command , this does not apply to your problem, but I suggest you not copy the line to the buffer, but use the line instead:
//char command_buffer[255]; //strcpy(command_buffer, command.c_str()); //n = write(sockfd,command_buffer,strlen(command_buffer)); n = write(sockfd,command.c_str(),command.length());
paolo source share