{"id":130,"date":"2023-09-20T12:13:30","date_gmt":"2023-09-20T04:13:30","guid":{"rendered":"https:\/\/www.waidts.com\/?p=130"},"modified":"2023-09-20T14:20:47","modified_gmt":"2023-09-20T06:20:47","slug":"linux-%e4%bd%bf%e7%94%a8-mail-mailx-%e7%99%bc%e9%80%81%e9%83%b5%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.waidts.com\/index.php\/2023\/09\/20\/linux-%e4%bd%bf%e7%94%a8-mail-mailx-%e7%99%bc%e9%80%81%e9%83%b5%e4%bb%b6\/","title":{"rendered":"Linux \u4f7f\u7528 mail\/mailx \u767c\u9001\u90f5\u4ef6"},"content":{"rendered":"\n<p>\u5728Linux\u4f3a\u670d\u5668\u7dad\u8b77\u7684\u6642\u5019\uff0c\u767c\u9001\u90f5\u4ef6\u6709\u6642\u5f88\u6709\u5fc5\u8981\uff0c\u7576\u6aa2\u6e2c\u5230\u670d\u52d9\u3001\u7a0b\u5f0f\u6709\u554f\u984c\u6642\uff0c\u53ef\u4ee5\u53ca\u6642\u767c\u9001\u90f5\u4ef6\u901a\u77e5\u60a8\u8655\u7406\uff0c\u7576\u7136\u53ef\u4ee5\u81ea\u5df1\u5beb\u500b\u7a0b\u5f0f\u4f86\u767c\u9001\uff0cmailx\u5df2\u7d93\u5f88\u5f37\u5927\u3002<\/p>\n\n\n\n<p>\u5b89\u88dd\u524d\u63d0\u78ba\u4fdd\u95dc\u9589\u672c\u6a5f\u7684sendmail\u670d\u52d9\u6216postfix\u670d\u52d9<br>sendmail<br># service sendmail stop<br># chkconfig sendmail off<br>postfix<br># service postfix stop<br># chkconfig postfix off<\/p>\n\n\n\n<p>\u5b89\u88dd mailx<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># ubuntu\/debian<br>$ sudo apt-get install heirloom-mailx<br><br># fedora\/centos<br>$ sudo yum install mailx<\/code><\/pre>\n\n\n\n<p>1. \u7c21\u55ae\u7684\u90f5\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mail -s \"This is the subject\" someone@example.com<br>Hi someone<br>How are you<br>I am fine<br>Bye<br>EOT<\/code><\/pre>\n\n\n\n<p>\u8f38\u5165\u7b2c\u4e00\u884c\u547d\u4ee4\uff0c\u56de\u8eca\u4e4b\u5f8c\u5c31\u53ef\u4ee5\u8f38\u5165\u90f5\u4ef6\u7684\u5167\u5bb9\u4e86\uff0c\u5b8c\u6210\u8f38\u5165\u5167\u5bb9\u5f8c\u6309 CTRL+D \uff0cmailx \u5c31\u6703\u986f\u793a\u51fa EOT\u3002<\/p>\n\n\n\n<p>2. \u4f7f\u7528\u6a94\u4e2d\u7684\u53d6\u90f5\u4ef6\u5167\u5bb9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mail -s \"This is Subject\" someone@example.com &lt; \/path\/to\/file<\/code><\/pre>\n\n\n\n<p>\u6216\u8005\u53ef\u4ee5\u4f7f\u7528 echo<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"This is message body\" | mail -s \"This is Subject\" someone@example.com<\/code><\/pre>\n\n\n\n<p>3. \u591a\u500b\u6536\u4ef6\u4eba<\/p>\n\n\n\n<p>\u591a\u500b\u6536\u4ef6\u4eba\uff0c\u6536\u4ef6\u4f4d\u5740\u53ea\u9700\u8981\u7528\u9017\u865f\u201c\uff0c\u201d\u9694\u958b\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"This is message body\" | mail -s \"This is Subject\" someone@example.com,someone2@example.com<\/code><\/pre>\n\n\n\n<p>4. \u6284\u9001\u548c\u5bc6\u9001CC,BCC<\/p>\n\n\n\n<p>\u7528 -c \u8868\u793a\u6284\u9001\uff0c-b \u8868\u793a\u5bc6\u9001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"This is message body\" | mail -s \"This is Subject\" -c ccuser@example.com someone@example.com<\/code><\/pre>\n\n\n\n<p>5. \u5b9a\u7fa9\u5bc4\u4ef6\u8005\u8cc7\u8a0a<\/p>\n\n\n\n<p>\u4f7f\u7528 -r \u5b9a\u7fa9\u5bc4\u4ef6\u8005<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"This is message body\" | mail -s \"This is Subject\" -r \"Harry&lt;harry@gmail.com&gt;\" someone@example.com<\/code><\/pre>\n\n\n\n<p>6. \u4f7f\u7528\u7279\u6b8a\u7684\u56de\u5fa9\u4f4d\u5740<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u56de\u5fa9\u5730\u5740<br>$ echo \"This is message\" | mail -s \"Testing replyto\" -S replyto=\"mark@gmail.com\" someone@example.com<br><br># \u56de\u5fa9\u5730\u5740\u548c\u540d\u7a31<br>$ echo \"This is message\" | mail -s \"Testing replyto\" -S replyto=\"Mark&lt;mark@gmail.com&gt;\" someone@example.com<\/code><\/pre>\n\n\n\n<p>7. \u767c\u9001\u9644\u4ef6<\/p>\n\n\n\n<p>\u4f7f\u7528 &#8220;-a&#8221; \u52a0\u4e0a\u6a94\u8def\u5f91\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"This is message body\" | mail -s \"This is Subject\" -r \"Harry&lt;harry@gmail.com&gt;\" -a \/path\/to\/file someone@example.com<\/code><\/pre>\n\n\n\n<p>8. \u4f7f\u7528\u5916\u90e8\u7684SMTP\u4f3a\u670d\u5668<\/p>\n\n\n\n<p>\u4f7f\u7528\u5916\u90e8\u7684SMTP\u4f3a\u670d\u5668\uff0c\u9019\u6a23\u5c31\u53ef\u4ee5\u4e0d\u7528\u81ea\u5df1\u67b6\u8a2d\u90f5\u4ef6\u4f3a\u670d\u5668\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"This is the message body and contains the message\" | mailx -v -r \"someone@example.com\" -s \"This is the subject\" -S smtp=\"mail.example.com:587\" -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user=\"someone@example.com\" -S smtp-auth-password=\"abc123\" -S ssl-verify=ignore yourfriend@gmail.com<\/code><\/pre>\n\n\n\n<p>\u6216\u8005\u4f7f\u7528\u63db\u884c\u7684\u5f62\u5f0f\uff0c\u53ef\u8b80\u6027\u66f4\u5f37<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"This is the message body and contains the message\" | mailx -v \\<br>&gt; -r \"someone@example.com\" \\<br>&gt; -s \"This is the subject\" \\<br>&gt; -S smtp=\"mail.example.com:587\" \\<br>&gt; -S smtp-use-starttls \\<br>&gt; -S smtp-auth=login \\<br>&gt; -S smtp-auth-user=\"someone@example.com\" \\<br>&gt; -S smtp-auth-password=\"abc123\" \\<br>&gt; -S ssl-verify=ignore \\<br>&gt; yourfriend@gmail.com<\/code><\/pre>\n\n\n\n<p>9. \u914d\u7f6e\u5916\u90e8\u7684SMTP\u4f3a\u670d\u5668<\/p>\n\n\n\n<p>vim \/etc\/mail.rc \u5728\u6700\u5f8c\u6dfb\u52a0\u500b\u80fd\u767c\u9001\u90f5\u4ef6\u7684\u5e33\u865f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set smtp=\"mail.example.com:587\"<br>set smtp-use-starttls<br>set smtp-auth=login<br>set smtp-auth-user=\"someone@example.com\"<br>set smtp-auth-password=\"abc123\"<br>set ssl-verify=ignore<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Linux\u4f3a\u670d\u5668\u7dad\u8b77\u7684\u6642\u5019\uff0c\u767c\u9001\u90f5\u4ef6\u6709\u6642\u5f88\u6709\u5fc5\u8981\uff0c\u7576\u6aa2\u6e2c\u5230\u670d\u52d9\u3001\u7a0b\u5f0f\u6709\u554f\u984c\u6642\uff0c\u53ef\u4ee5\u53ca\u6642\u767c\u9001\u90f5\u4ef6\u901a\u77e5\u60a8\u8655\u7406\uff0c\u7576 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.waidts.com\/index.php\/2023\/09\/20\/linux-%e4%bd%bf%e7%94%a8-mail-mailx-%e7%99%bc%e9%80%81%e9%83%b5%e4%bb%b6\/\"> <span class=\"screen-reader-text\">Linux \u4f7f\u7528 mail\/mailx \u767c\u9001\u90f5\u4ef6<\/span> \u95b1\u8b80\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-130","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/comments?post=130"}],"version-history":[{"count":4,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":134,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/posts\/130\/revisions\/134"}],"wp:attachment":[{"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.waidts.com\/index.php\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}