How to use the command 'sendmail' (with examples)

How to use the command 'sendmail' (with examples)

The command sendmail is used to send email from the command line. It is a powerful utility that allows users to send emails directly without the need for a graphical email client.

Use case 1: Send a message to a local user

Code:

sendmail username < message.txt

Motivation: Sending a message to a local user can be useful for system notifications or personal communication. By using the sendmail command, you can directly send a message to a specific user without the need for any additional email client software.

Explanation: In this use case, the username parameter represents the local user to whom the email will be sent. The < message.txt part is used to specify the content of the email, which is taken from the message.txt file.

Example output: The content of message.txt will be sent as an email to the mail directory of the specified username.

Use case 2: Send an email using a specific sender address

Code:

sendmail -f you@yourdomain.com test@gmail.com < message.txt

Motivation: Sometimes it is necessary to send an email on behalf of a specific email address. By using the -f option, you can specify the sender address to be used for the email.

Explanation: In this use case, the -f you@yourdomain.com argument is used to specify the sender address, which could be any valid email address. The test@gmail.com parameter represents the recipient’s email address. The < message.txt part is used to provide the content of the email from the message.txt file.

Example output: The email will be sent from the specified sender address (you@yourdomain.com) to the recipient email address (test@gmail.com) containing the message specified in message.txt.

Use case 3: Send an email with an attachment

Code:

sendmail -f you@yourdomain.com test@gmail.com < file.zip

Motivation: Sending an email with an attachment is often required when sharing files with others. Instead of using a graphical email client, the sendmail command allows you to send emails with attachments directly from the command line.

Explanation: In this use case, the -f you@yourdomain.com argument is used to specify the sender address. The test@gmail.com parameter represents the recipient’s email address. The < file.zip part is used to provide the attachment file, which in this case is file.zip.

Example output: The email will be sent from the specified sender address (you@yourdomain.com) to the recipient email address (test@gmail.com) containing the file.zip attachment.

Conclusion:

The sendmail command is a powerful tool for sending emails directly from the command line. It provides flexibility in specifying the sender address, recipient email, and content of the email. By using this command, users can send emails without the need for a graphical email client, making it a convenient option for automation or server-based email communication.

Related Posts

How to use the command asciiart (with examples)

How to use the command asciiart (with examples)

The asciiart command is a tool that allows you to convert images to ASCII art.

Read More
How to use the command ksvgtopng5 (with examples)

How to use the command ksvgtopng5 (with examples)

The ksvgtopng5 command is a utility that allows you to convert Scalable Vector Graphics (SVG) files to Portable Network Graphics (PNG) format.

Read More
How to use the command 'udevadm' (with examples)

How to use the command 'udevadm' (with examples)

‘udevadm’ is a Linux management tool used for managing various aspects of the udev device manager.

Read More