{"id":3752,"date":"2022-12-30T14:10:18","date_gmt":"2022-12-30T06:10:18","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3752"},"modified":"2022-12-30T14:10:18","modified_gmt":"2022-12-30T06:10:18","slug":"%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84smtp%e5%8d%94%e8%ad%b0","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/go\/%e5%ad%b8%e7%bf%92go%e8%aa%9e%e8%a8%80%e4%b8%ad%e7%9a%84smtp%e5%8d%94%e8%ad%b0\/","title":{"rendered":"\u5b78\u7fd2Go\u8a9e\u8a00\u4e2d\u7684SMTP\u5354\u8b70"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Go, SMTP, \u5354\u8b70\"><\/p>\n<h1>\u4f7f\u7528 Go \u8a9e\u8a00\u638c\u63e1 SMTP \u5354\u8b70<\/h1>\n<p>SMTP\uff08Simple Mail Transfer Protocol\uff09\u662f\u4e00\u7a2e\u7528\u65bc\u5728\u7db2\u969b\u7db2\u8def\u4e0a\u50b3\u9001\u96fb\u5b50\u90f5\u4ef6\u7684\u6a19\u6e96\u5354\u8b70\u3002\u5b83\u662f\u4e00\u7a2e\u5ba2\u6236\u7aef\/\u4f3a\u670d\u5668\u5354\u8b70\uff0c\u5141\u8a31\u7528\u6236\u7aef\u767c\u9001\u90f5\u4ef6\u5230\u4f3a\u670d\u5668\uff0c\u4e26\u5141\u8a31\u4f3a\u670d\u5668\u5c07\u90f5\u4ef6\u50b3\u9001\u5230\u5176\u4ed6\u4f3a\u670d\u5668\u3002<\/p>\n<p>Go \u8a9e\u8a00\u662f\u4e00\u7a2e\u958b\u6e90\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u958b\u767c\u9ad8\u6548\u7684\u7db2\u8def\u61c9\u7528\u7a0b\u5f0f\u3002Go \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u500b\u5167\u5efa\u7684 SMTP \u5305\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u4f7f\u7528 SMTP \u5354\u8b70\u4f86\u767c\u9001\u96fb\u5b50\u90f5\u4ef6\u3002<\/p>\n<h2>Go \u8a9e\u8a00 SMTP \u5305\u7684\u4f7f\u7528<\/h2>\n<p>Go \u8a9e\u8a00\u7684 SMTP \u5305\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u4f7f\u7528 SMTP \u5354\u8b70\u4f86\u767c\u9001\u96fb\u5b50\u90f5\u4ef6\u3002\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\uff0c\u53ef\u4ee5\u8b93\u4f60\u5feb\u901f\u958b\u59cb\u4f7f\u7528 Go \u8a9e\u8a00\u7684 SMTP \u5305\uff1a<\/p>\n<pre class=\"brush: go\">\npackage main\n\nimport (\n    \"net\/smtp\"\n    \"log\"\n)\n\nfunc main() {\n    \/\/ \u8a2d\u5b9a SMTP \u4f3a\u670d\u5668\u8cc7\u8a0a\n    smtpServer := \"smtp.example.com\"\n    auth := smtp.PlainAuth(\"\", \"user@example.com\", \"password\", smtpServer)\n\n    \/\/ \u767c\u9001\u90f5\u4ef6\n    to := []string{\"recipient@example.net\"}\n    msg := []byte(\"To: recipient@example.net\\r\\n\" +\n        \"Subject: discount Gophers!\\r\\n\" +\n        \"\\r\\n\" +\n        \"This is the email body.\\r\\n\")\n    err := smtp.SendMail(smtpServer+\":587\", auth, \"sender@example.org\", to, msg)\n    if err != nil {\n        log.Fatal(err)\n    }\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u793a\u7bc4\u4e86\u5982\u4f55\u4f7f\u7528 Go \u8a9e\u8a00\u7684 SMTP \u5305\u4f86\u767c\u9001\u96fb\u5b50\u90f5\u4ef6\u3002\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u8a2d\u5b9a SMTP \u4f3a\u670d\u5668\u7684\u8cc7\u8a0a\uff0c\u7136\u5f8c\u4f7f\u7528 <code>smtp.SendMail()<\/code> \u65b9\u6cd5\u4f86\u767c\u9001\u90f5\u4ef6\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>Go \u8a9e\u8a00\u63d0\u4f9b\u4e86\u4e00\u500b\u5167\u5efa\u7684 SMTP \u5305\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5730\u4f7f\u7528 SMTP \u5354\u8b70\u4f86\u767c\u9001\u96fb\u5b50\u90f5\u4ef6\u3002\u4f7f\u7528 Go \u8a9e\u8a00\u7684 SMTP \u5305\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u51fa\u9ad8\u6548\u7684\u7db2\u8def\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39Go\u8a9e\u8a00\u4e2d\u7684SMTP\u5354\u8b70\uff0c\u8a73\u7d30\u89e3\u91cbSMTP\u5354\u8b70\u7684\u529f\u80fd\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528Go\u8a9e\u8a00\u4f86\u5be6\u73feSMTP\u5354\u8b70\u3002\u672c\u6587\u5c07\u70ba\u60a8\u63d0\u4f9b\u6709\u95dcSMTP\u5354\u8b70\u7684\u6700\u65b0\u8cc7\u8a0a\uff0c\u8b93\u60a8\u66f4\u52a0\u4e86\u89e3Go\u8a9e\u8a00\u4e2d\u7684SMTP\u5354\u8b70\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[171,172],"tags":[169,170],"class_list":["post-3752","post","type-post","status-publish","format-standard","hentry","category-go","category-golang","tag-go","tag-golang"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-Yw","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=3752"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3752\/revisions"}],"predecessor-version":[{"id":3753,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3752\/revisions\/3753"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}