{"id":4046,"date":"2019-04-18T20:20:14","date_gmt":"2019-04-18T12:20:14","guid":{"rendered":"http:\/\/blog.hoyo.idv.tw\/?p=4046"},"modified":"2022-02-22T08:50:32","modified_gmt":"2022-02-22T00:50:32","slug":"postfix-%e4%bd%bf%e7%94%a8-mysql-%e8%b3%87%e6%96%99%e5%ba%ab%e8%99%9b%e6%93%ac%e4%bd%bf%e7%94%a8%e8%80%85-2-mysql-etc-postfix-mysql-virtual-maps-cf","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=4046","title":{"rendered":"Postfix \u4f7f\u7528 MySQL \u8cc7\u6599\u5eab\u865b\u64ec\u4f7f\u7528\u8005 - 2. mysql:\/etc\/postfix\/mysql-virtual-maps.cf"},"content":{"rendered":"<p>\u96d6\u7136\u4f7f\u7528\u00a0virtual_mailbox_maps = \u00a0\/etc\/postfix\/virtual \u5c0d\u61c9\u5230\u4e00\u500b\u6587\u5b57\u6a94\u6848\u7ba1\u7406\u5e33\u865f\u8cc7\u8a0a\uff0c\u78ba\u5be6\u53ef\u4ee5\u6e1b\u5c11\u65b0\u589e\u7dad\u8b77\u5be6\u9ad4\u672c\u6a5f\u5e33\u865f\u7684\u5de5\u4f5c\u4ee5\u53ca\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8cc7\u5b89\u554f\u984c\uff0c\u4e0d\u904e\u4eba\u90fd\u662f\u4e0d\u6eff\u8db3\u7684\uff0c\u6bcf\u6b21\u90fd\u8981\u5148 vi \u4e00\u4e0b\u518d postmap \u5be6\u5728\u662f\u592a\u9ebb\u7169\u4e86\uff0c\u6709\u66f4\u65b9\u4fbf\u7684\u65b9\u5f0f\u55ce\uff1f<\/p>\n<p>\u4e0d\u59a8\u8a66\u8a66\u4f7f\u7528 MySQL \u8cc7\u6599\u5eab\u4f86\u7ba1\u7406\u5e33\u865f ...<\/p>\n<p>--<\/p>\n<h2>\u53c3\u8003<\/h2>\n<ul>\n<li><a href=\"https:\/\/wiki.gentoo.org\/wiki\/Complete_Virtual_Mail_Server\/Postfix_to_Database\" target=\"_blank\" rel=\"noopener noreferrer\">Complete Virtual Mail Server\/Postfix to Database<\/a><\/li>\n<li><a href=\"https:\/\/serverfault.com\/questions\/722137\/how-to-specify-target-directory-in-postfix-with-mysql\">How to specify target directory in Postfix with MySQL?<\/a><\/li>\n<\/ul>\n<p>\u8f49\u63db\u70ba MySQL \u8cc7\u6599\u5eab\u7576\u4f5c\u4f7f\u7528\u8005\u5e33\u865f\u662f\u4ee5\u00a0<a href=\"https:\/\/blog.hoyo.idv.tw\/?p=4041\" target=\"_blank\" rel=\"noopener\">Postfix \u4f7f\u7528\u865b\u64ec\u4f7f\u7528\u8005 - 1. \/etc\/postfix\/virtual<\/a> \u57fa\u790e\u4f86\u4fee\u6539\uff0c\u6240\u4ee5\u8acb\u5f9e\u982d\u5be6\u505a<\/p>\n<p>--<\/p>\n<h2>MySQL \u8cc7\u6599\u5eab\u7684\u6e96\u5099<\/h2>\n<p>\u5efa\u7acb\u8cc7\u6599\u5eab\u4f7f\u7528\u8005\u5e33\u865f<\/p>\n<p>&nbsp;<\/p>\n<p>\u4f7f\u7528\u8005\u5e33\u865f\u8cc7\u6599\u8868<\/p>\n<pre class=\"height-set:true lang:default decode:true\">CREATE TABLE `UserAlias` (\r\n  `id` int(11) NOT NULL auto_increment,\r\n  `Create_Time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '\u5efa\u7acb\u6642\u9593',\r\n  `Email` varchar(200) NOT NULL,\r\n  `Password` char(40) NOT NULL,\r\n  PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;<\/pre>\n<p>\u65b0\u589e\u4f7f\u7528\u8005<\/p>\n<pre class=\"lang:default decode:true \">INSERT INTO `UserAlias` (`Email`) VALUES('aaa@mail.hoyo.idv.tw');<\/pre>\n<p>--<\/p>\n<h2>Postfix \u8a2d\u5b9a<\/h2>\n<p>\/etc\/postfix\/main.cf<\/p>\n<pre class=\"lang:default decode:true\"># \u8a3b\u89e3 virtual_mailbox_maps = hash:\/etc\/postfix\/virtual\r\nvirtual_mailbox_maps = mysql:\/etc\/postfix\/mysql-aliases.cf<\/pre>\n<p style=\"color: #333333; font-style: normal;\">\u91cd\u65b0\u555f\u52d5 postfix<\/p>\n<pre class=\"lang:default decode:true\" style=\"color: #333333; font-style: normal; font-weight: 300;\"># systemctl restart postfix<\/pre>\n<p>\/etc\/postfix\/mysql-virtual-maps.cf<\/p>\n<pre class=\"lang:default decode:true\">hosts = 127.0.0.1\r\nuser = Postfix\r\npassword = Postfix\r\ndbname = Postfix\r\nquery = SELECT '%d\/%u\/' FROM `UserAlias` WHERE Email='%s'<\/pre>\n<ul>\n<li>'%d\/%u\/' \u56de\u50b3 <strong>\u7db2\u57df\u540d\u7a31\/\u5e33\u865f\u540d\u7a31\/<\/strong> \u683c\u5f0f\uff0c\u4f8b\u5982\uff1amail.hoyo.idv.tw\/aaa\/<\/li>\n<\/ul>\n<p>\u6e2c\u8a66\u662f\u5426\u53ef\u53d6\u5f97\u503c\u4ee5\u53ca\u53d6\u5230\u4ec0\u9ebc\u503c\uff0c\u5982\u679c\u6c92\u56de\u50b3\u5c31\u4ee3\u8868\u6709\u932f\u8aa4<\/p>\n<pre class=\"lang:default decode:true\"># postmap -q aaa@mail.hoyo.idv.tw mysql:\/etc\/postfix\/mysql-virtual-maps.cf\r\nmail.hoyo.idv.tw\/aaa\/<\/pre>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"4046\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,168&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u96d6\u7136\u4f7f\u7528\u00a0virtual_ma...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"4046\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,168&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[317],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4046"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4046"}],"version-history":[{"count":29,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4046\/revisions"}],"predecessor-version":[{"id":9544,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4046\/revisions\/9544"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}