• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Sending an email using curl c++

Resolved: Sending an email using curl c++

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Im trying to send an email using curl c++, i managed to log in well and when i run the program it works fine, does not throw any error, but the email never comes.
This is my code:
I think the problem is in the curl options READDATA and READUNCTION. In the documentation says that you have to pass as an argument to READDATA a data pointer. const char *data = payload_text; is the data pointer, right?
then READFUNCTION takes as an argument a function which return the size of the data and i think that is what size_t read_function(char *buffer, size_t size, size_t nmemb,char *data) is doing.
I am new in this so any advice would be good for me.

Answer:

I found this to be a helpful starting point: https://curl.se/libcurl/c/smtp-mail.html
There are two main problems with your code:
  1. Your read_function didn’t keep track of how much of the payload has been read so it would keep giving the same content to libcurl over and over and never signal the end of the message.
  2. You were setting CURLOPT_MAIL_RCPT to a string when in fact it should be a struct curl_slist * because there can be multiple recipients.

Here is a fixed example that I tested on my computer and it worked. Private data at the top of the file was modified before posting.

If you have better answer, please add a comment about this, thank you!

c++
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Shopware 400 Status Error “This value is too long. It should have 255 character or less.” When I Try Updating Database Table

01/04/2023

Resolved: Using AWK to count multiple patterns in a file

01/04/2023

Resolved: significance letter above bar graphic in wrong order

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.