cSMTP is a simple SMTP (Simple Mail Transfer Protocol) client written in C. It demonstrates the basics of connecting to an SMTP server, sending email commands, and transmitting an email message from a source to a destination address.
- Establishes a connection to an SMTP server
- Sends
HELO
,MAIL FROM
,RCPT TO
, andDATA
commands - Reads server responses
- Handles simple email sending with specified source and destination addresses
Csmtp.c
: The main program file containing the implementation of the SMTP client.Csmtp.h
: The header file containing function prototypes and necessary includes.
To compile and run the cSMTP client, you need:
- A C compiler (e.g.,
gcc
) - A Unix-like operating system (Linux, macOS, etc.)
- Network access to an SMTP server
- Clone the repository:
git clone https://github.com/yourusername/cSMTP.git
- Navigate to the repository directory:
cd cSMTP
- Compile the code:
gcc -o cSMTP Csmtp.c
To run the cSMTP client, use the following command:
./cSMTP <file_with_addresses> <smtp_server> [port_number]
<file_with_addresses>
: A file containing the source and destination email addresses. The source address should be on the first line, and the destination address on the second line.<smtp_server>
: The hostname or IP address of the SMTP server.[port_number]
(optional): The port number of the SMTP server (default is 25).
./cSMTP addresses.txt smtp.example.com 587
In this example, addresses.txt
contains:
source@example.com
destination@example.com
The main implementation file for the cSMTP client. It includes:
- Establishing a connection to the SMTP server
- Sending SMTP commands and handling server responses
- Reading email addresses from a file
- Sending email content from the file
The header file defining function prototypes and necessary includes for the SMTP client.
int main(int argc, char **argv)
: The main function to execute the SMTP client.int getLine(int fd, char* line, int lim)
: Reads a line of data from the socket.void readServer(int fd, char *line, int *lim, char *postfix)
: Reads the server response.int checkReply(char reply)
: Checks the server reply code.char* getPostfix(char* header, char* postfix)
: Extracts postfix from the server reply header.
char* getPostfix(char *header, char *postfix)
: Function prototype for extracting postfix from server reply header.void readServer(int fd, char *line, int* lim, char *postfix)
: Function prototype for reading server response.int checkReply(char reply)
: Function prototype for checking server reply code.int getLine(int fd, char line[], int max)
: Function prototype for getting a line of data from the socket.
This project is licensed under the MIT License. See the LICENSE
file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project was created by Uriel Shani as a simple demonstration of an SMTP client in C.
For any questions or issues, please contact the repository owner.