Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smtp client - from and to not send

Tags:

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

enter image description here

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

like image 377
abdoe Avatar asked Dec 18 '17 06:12

abdoe


People also ask

Why is SMTP not sending emails?

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.

Why does my email receive but not send?

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.

How do you change SMTP and other settings in email client?

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.

What port do you need to close to block outgoing email?

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.


1 Answers

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:

  1. don't start the data section with an empty line;
  2. add an empty line before the message text.

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());
like image 175
p-a-o-l-o Avatar answered Oct 13 '22 11:10

p-a-o-l-o