I have an smtp client build in c++ where I can send emails to my testing mailtrap account. The headers are send and the email is arriving just fine.
My problem is, that the field which indicates from/to is empty - as displayed in the screenshot
I'm sending the header with
write_command("MAIL FROM: <[email protected]>");
write_command("RCPT TO: <[email protected]>");
I made a gist with my full code of the Smtp client
https://gist.github.com/anonymous/7bb13de7f044bcb5d07d0e6a9d991ea9
I'm calling it from my main()
function
with
Smtp smtp_client = Smtp();
smtp_client.new_connection("smtp.mailtrap.io", 25);
smtp_client.auth_login("username", "password");
smtp_client.sendmail();
smtp_client.close_connection();
thanks for tacking a look
Check whether there is network access from CSO to the SMTP server. Check whether the firewall is blocking SMTP traffic to SMTP server or whether the ports are blocked. If the server settings and authentication settings are correct, check whether the firewall is blocking port 587 and 465 and SMTP traffic.
If you can receive emails but can not send emails this usually means the authenication required by the outgoing (SMTP) server is not configured. If you can't send or receive emails the chances are your IP address has been auto banned, please go to this article instead.
Locate your email account and highlight it to select it. Click on the "Properties" button. Select the "Advanced" tab, and in the "Outgoing Server (SMTP)" field, first delete out the existing value "25" and then type in its place "587". Select the "OK" or "Apply" button to save your changes.
Many email clients and services use port 25 for SMTP to send out emails. However an ISP (Internet Service Provider) may block port 25 in order to prevent spamming by its customers.
I managed to make the fields appear, editing your sendmail
function a bit:
void sendmail()
{
write_command("MAIL FROM: <[email protected]>");
write_command("RCPT TO: <[email protected]>");
write_command("DATA");
std::string data;
data.append("MIME-Version: 1.0\r\n");
data.append("From: <[email protected]>\r\n");
data.append("To: <[email protected]>\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"); //this seems to matter
data.append("This is a test");
data.append("\r\n.");
write_command(data);
write_command("QUIT");
}
I put the whole DATA in a string and sent it in a single write.
What (apparently) matters:
I also edited your write_command
, it doesn't relate to your issue but I suggest you don't copy the string to a buffer but directly use the string 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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With