A c program that can sends mail to others

Here is a simple C program that uses the sendmail command to send an email to another user:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LINE 1024

int main() {
    char from[256];
    char to[256];
    char subject[256];
    char message[1024];

    printf("Enter your email address: ");
    fgets(from, 256, stdin);
    from[strcspn(from, "\n")] = 0; // remove newline character

    printf("Enter the recipient's email address: ");
    fgets(to, 256, stdin);
    to[strcspn(to, "\n")] = 0; // remove newline character

    printf("Enter the subject: ");
    fgets(subject, 256, stdin);
    subject[strcspn(subject, "\n")] = 0; // remove newline character

    printf("Enter the message: ");
    fgets(message, 1024, stdin);
    message[strcspn(message, "\n")] = 0; // remove newline character

    char command[256];
    sprintf(command, "sendmail -t -i -f %s -t %s -s %s -m %s", from, to, subject, message);

    system(command);

    printf("Email sent successfully!\n");

    return 0;
}

This program uses the sendmail command to send an email. The sendmail command is a Unix command that sends email messages to a mail server. The options used in the command are:

You can compile this program using the following command:

gcc sendmail.c -o sendmail

You can run the program by typing:

./sendmail

This will prompt you to enter your email address, the recipient's email address, the subject, and the message. After you enter the information, the program will send the email using the sendmail command.

Note: This program assumes that the sendmail command is installed on your system and that you have a mail server set up to receive emails. If you don't have a mail server set up, you may need to use a different method to send emails.