<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>https://wiki.webko.net.ua/index.php?action=history&amp;feed=atom&amp;title=Mail_%D1%81_%D0%BA%D0%BE%D0%BD%D1%81%D0%BE%D0%BB%D0%B8</id>
	<title>Mail с консоли - История изменений</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.webko.net.ua/index.php?action=history&amp;feed=atom&amp;title=Mail_%D1%81_%D0%BA%D0%BE%D0%BD%D1%81%D0%BE%D0%BB%D0%B8"/>
	<link rel="alternate" type="text/html" href="https://wiki.webko.net.ua/index.php?title=Mail_%D1%81_%D0%BA%D0%BE%D0%BD%D1%81%D0%BE%D0%BB%D0%B8&amp;action=history"/>
	<updated>2026-05-13T10:59:58Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://wiki.webko.net.ua/index.php?title=Mail_%D1%81_%D0%BA%D0%BE%D0%BD%D1%81%D0%BE%D0%BB%D0%B8&amp;diff=87&amp;oldid=prev</id>
		<title>Sol: Новая страница: «Отправка електронных писем с консоли  Полезно для отправки автоматических отчетов.  Жля…»</title>
		<link rel="alternate" type="text/html" href="https://wiki.webko.net.ua/index.php?title=Mail_%D1%81_%D0%BA%D0%BE%D0%BD%D1%81%D0%BE%D0%BB%D0%B8&amp;diff=87&amp;oldid=prev"/>
		<updated>2015-04-20T17:56:42Z</updated>

		<summary type="html">&lt;p&gt;Новая страница: «Отправка електронных писем с консоли  Полезно для отправки автоматических отчетов.  Жля…»&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Отправка електронных писем с консоли&lt;br /&gt;
&lt;br /&gt;
Полезно для отправки автоматических отчетов.&lt;br /&gt;
&lt;br /&gt;
Жля начала нам нужен mailx&lt;br /&gt;
 yum install mailx&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Синтаксис ==&lt;br /&gt;
&lt;br /&gt;
Отправить произвольное сообщение:&lt;br /&gt;
 # echo “test-test-test” | mail -s “Subject” username@example.com&lt;br /&gt;
&lt;br /&gt;
Отправить файл в теле письма:&lt;br /&gt;
 # mail -s “Subject” username@example.com &amp;lt; /var/log/messages&lt;br /&gt;
&lt;br /&gt;
Отправить письмо в интерактивном режиме:&lt;br /&gt;
 # mail -s “Subject” username@example.com&lt;br /&gt;
 test-test-test&lt;br /&gt;
 .&lt;br /&gt;
 Cc:&lt;br /&gt;
 # &lt;br /&gt;
(В конце тела письма обязательно строчка с единственной точной)&lt;br /&gt;
 echo &amp;quot;Message Body&amp;quot; | mail -s &amp;quot;Message Subject&amp;quot; receiver@example.com&lt;br /&gt;
 &lt;br /&gt;
 ./crypto_php_check.py /var/www/ | grep &amp;quot;CRYPTOPHP DETECTED&amp;quot; | mail -s &amp;quot;Crypto php&amp;quot; nua@webko.net.ua&lt;br /&gt;
&lt;br /&gt;
And if you want mail to read the content from a file:&lt;br /&gt;
 mail -s “Hello world” you@youremailid.com &amp;lt; /home/calvin/application.log&lt;br /&gt;
Some other useful options in the mail command are:&lt;br /&gt;
-s subject (The subject of the mail)&lt;br /&gt;
-c email-address (Mark a copy to this “email-address”, or CC)&lt;br /&gt;
-b email-address (Mark a blind carbon copy to this “email-address”, or BCC)&lt;br /&gt;
Here’s how you might use these options:&lt;br /&gt;
 echo “Welcome to the world of Calvin n Hobbes” | mail -s “Hello world” calvin@cnh.com -c hobbes@cnh.com -b susie.derkins@cnh.com&lt;br /&gt;
&lt;br /&gt;
'''MUTT'''&lt;br /&gt;
&lt;br /&gt;
One of major drawbacks of using the mail command is that it does not support the sending of attachments. mutt, on the other hand, does support it. I’ve found this feature particularly useful for scripts that generate non-textual reports or backups which are relatively small in size which I’d like to backup elsewhere. Of course, mutt allows you to do a lot more than just send attachments. It is a much more complete command line mail client than the “mail” command. Right now we’ll just explore the basic stuff we might need often. Here’s how you would attach a file to a mail:&lt;br /&gt;
 echo “Sending an attachment.” | mutt -a backup.zip -s “attachment” calvin@cnh.com&lt;br /&gt;
This command will send a mail to calvin@cnh.com with the subject (-s) “attachment”, the body text “Sending an attachment.”, containing the attachment (-a) backup.zip. Like with the mail command you can use the “-c” option to mark a copy to another mail id.&lt;br /&gt;
&lt;br /&gt;
'''SENDING MAIL FROM A SHELL SCRIPT'''&lt;br /&gt;
&lt;br /&gt;
Now, with the basics covered you can send mails from your shell scripts. Here’s a simple shell script that gives you a reading of the usage of space on your partitions and mails the data to you.&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 df -h | mail -s “disk space report” calvin@cnh.com&lt;br /&gt;
&lt;br /&gt;
Save these lines in a file on your Linux server and run it. You should receive a mail containing the results of the command. If, however, you need to send more data than just this you will need to write the data to a text file and enter it into the mail body while composing the mail. Here’s and example of a shell script that gets the disk usage as well as the memory usage, writes the data into a temporary file, and then enters it all into the body of the mail being sent out:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 df -h &amp;gt; /tmp/mail_report.log&lt;br /&gt;
 free -m &amp;gt;&amp;gt; /tmp/mail_report.log&lt;br /&gt;
 mail -s “disk and RAM report” calvin@cnh.com &amp;lt; /tmp/mail_report.log&lt;br /&gt;
Now here’s a more complicated problem. You have to take a backup of a few files and mail then out. First the directory to be mailed out is archived. Then it is sent as an email attachment using mutt. Here’s a script to do just that:&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 tar -zcf /tmp/backup.tar.gz /home/calvin/files&lt;br /&gt;
 echo | mutt -a /tmp/backup.tar.gz -s “daily backup of data” calvin@cnh.com&lt;br /&gt;
The echo at the start of the last line adds a blank into the body of the mail being set out.&lt;br /&gt;
&lt;br /&gt;
[[Категория:Общее *nix]]&lt;/div&gt;</summary>
		<author><name>Sol</name></author>
	</entry>
</feed>