kascebear.blogg.se

Send mail using mail command in linux
Send mail using mail command in linux








send mail using mail command in linux
  1. #Send mail using mail command in linux how to#
  2. #Send mail using mail command in linux install#

If the mail fails to deliver due to an improperly configured mail server for example, the smtp command log will show what has gone wrong. Use the "-v" option for that $ mail -v -s "This is the subject" <<< 'This is the message' Sometimes when testing mail servers, you would want to check the SMTP commands being used by the mail command. You could also append to the username, where the hostname should be the hostname of the current system. To send mail to a local system user just use the username in place of the recipient address $ mail -s "Hello World" username When you are issuing the command from within some script, you would omit that. Note that we have to escape the less/great arrows since they have special meaning for the shell prompt. This is useful when calling the mail command from shell scripts or other programs written in perl or php for example. If the email message is in a file then we can use it directly to send the mail. To specify the message body in just one line of command use the following style $ mail -s "This is the subject" 3. Once you do that, the mail command would dispatch the message for delivery and done. Once you are done entering the message, press. Pressing enter would create a new line in the message. Enter the CC address and press enter or press enter without anything to skip.įrom the next line type in your message. The shell asks for the 'Cc' (Carbon copy) field. When you're done, hit 'Ctrl-D' at the beginning of a line $ mail -s "Hello World" The above command is not finished upon hitting Enter. Run the command below, to send an email to The s option specifies the subject of the mail followed by the recipient email address. If you try to send mail from you local machine or desktop, then most spam filters would probably block it. Note: If you are trying to send a test mail to some mail provider like gmail or outlook, then you would need to run these commands on a server with proper configuration. These examples shall give you a basic idea of the various options and features supported by the mail command.

#Send mail using mail command in linux how to#

Here are some examples of how to use the mail command to send mails from the command line. Now you should have the mail command ready to work.

#Send mail using mail command in linux install#

Use the apt-get command to install it $ apt-get install mailutils In this tutorial we shall be using the mail command from the mailutils package, which is available on most Debian and Ubuntu based systems. For example the mail/mailx command from the heirloom-mailx package is capable of using an external smtp server to send messages, while the other two can use only a local smtp server. Here is the list of some of the common packages that provide the mail command.Įach flavor has a different set of options and supported features. These packages are available in the default repositores of most of the popular linux distributions like debian, ubuntu, centos and fedora.

send mail using mail command in linux

The mail command is available from many different packages.

send mail using mail command in linux

If none is running you get the error message "send-mail: Cannot open mail:25". This means that an smtp server like Postfix should be running on the machine where you intend to use the mail command. mail command -> /usr/sbin/sendmail -> local MTA (smtp server) -> recipient MTA (and Inbox) The local MTA is a locally running smtp server that accepts mails on port 25. The mail command invokes the standard sendmail binary (/usr/sbin/sendmail) which in turns connects to the local MTA to send the mail to its destination.

send mail using mail command in linux

How the mail command worksįor those who are curious about how exactly the mail command delivers the mails to the recipients, here is a little quick explanation. This tutorial explains, how to use to the mail command on linux to send mails from the command-line using the mail command.










Send mail using mail command in linux