Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:21:21+00:00 2026-06-13T05:21:21+00:00

I am creating an SMTP client program in C on RHEL 4 Linux based

  • 0

I am creating an SMTP client program in C on RHEL 4 Linux based on the sample program at:

http://curl.haxx.se/libcurl/c/simplesmtp.html

Whenever I pass the message body text to the program through stdin, the program works correctly. However, I experience a segfault when I try to pass a FILE pointer to the curl_easy_setopt() function. The comments (from the sample program simplesmtp.c) state that it is possible to pass a file pointer instead of stdin to the curl_easy_setopt function.

Relevant comment section from simplesmtp.c

/* You provide the payload (headers and the body of the message) as the
 * "data" element. There are two choices, either:
 * - provide a callback function and specify the function name using the
 * CURLOPT_READFUNCTION option; or
 * - just provide a FILE pointer that can be used to read the data from.
 * The easiest case is just to read from standard input, (which is available
 * as a FILE pointer) as shown here.
 */ 
curl_easy_setopt(curl, CURLOPT_READDATA, stdin);

These are the error lines from the console with the CURLOPT_VERBOSE option set.

< 250 2.1.5 <myname@mydomain.com>... Recipient ok
> DATA
< 354 Enter mail, end with "." on a line by itself
./r: line 5: 21282 Segmentation fault      ./mysmtpcli -r rcp.txt -m msg.txt

BTW: ./r is my shell script which is calling ./mysmtpcli -r rcp.txt -m msg.txt

My Snippet of Code

FILE *f_msg;
f_msg = fopen(msg_file, "r");
if(!f_msg){
  fprintf(stderr, "Could not load message file: %s\n", msg_file);
  return 1;
}

curl_easy_setopt(curl, CURLOPT_READDATA, f_msg);

fclose(f_msg);

Note: The msg_file variable is populated from the command line parameters and is a valid text file containing:

Subject: Test Message

This is a test message!

When this same file is passed to the program via stdin using “cat msg.txt | ./mysmtpcli -r rcp.txt”, the program executes properly. Though, this requires replacing f_msg with stdin.

curl_easy_setopt(curl, CURLOPT_READDATA, f_msg);

Am I passing the FILE pointer correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:21:22+00:00Added an answer on June 13, 2026 at 5:21 am

    Yes, you do pass a file pointer correctly. Though it seems like you close it right away. If you do that, curl will later try to read from that file and crash. You have to close it only when it is not needed anymore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am manually creating a multi-part MIME-formatted file and submitting it to an SMTP
Creating a browser based single-page browser based RIA. Would like to make use of
Creating a C# install package and I'd like on completed install for the Program
I am creating a report on an asp.net web page using an html table
i am creating an email client that sends e-mail address from server ip instead
i am creating an email client that sends e-mail address from server ip instead
i am creating an Email sending sample application, and i want to use send
When I'm creating a user for my web application, an SMTP email (using ASP.NET's
I am creating and sending emails using the System.Net.Mail namespace. The smtp.Send(mailMessage) call is
I am currently working on creating my own SMTP server for a project I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.