{"id":207724,"date":"2025-07-08T14:00:44","date_gmt":"2025-07-08T06:00:44","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207724\/"},"modified":"2025-07-08T14:00:44","modified_gmt":"2025-07-08T06:00:44","slug":"golang-%e4%b8%ad%e4%b8%8e%e5%b7%b2%e9%aa%8c%e8%af%81%e7%9a%84%e5%8f%91%e4%bb%b6%e4%ba%ba%e8%ba%ab%e4%bb%bd%e4%b8%8d%e5%8c%b9%e9%85%8d%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207724\/","title":{"rendered":"golang \u4e2d\u4e0e\u5df2\u9a8c\u8bc1\u7684\u53d1\u4ef6\u4eba\u8eab\u4efd\u4e0d\u5339\u914d\u9519\u8bef"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>golang \u4e2d\u4e0e\u5df2\u9a8c\u8bc1\u7684\u53d1\u4ef6\u4eba\u8eab\u4efd\u4e0d\u5339\u914d\u9519\u8bef<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-24 23:45:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300agolang \u4e2d\u4e0e\u5df2\u9a8c\u8bc1\u7684\u53d1\u4ef6\u4eba\u8eab\u4efd\u4e0d\u5339\u914d\u9519\u8bef\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5904\u7406\u7528\u6237\u6ce8\u518c\u65f6\u53d1\u9001\u7684\u7535\u5b50\u90ae\u4ef6\u3002\u6211\u6b63\u5728\u514d\u8d39\u4f7f\u7528\u65b0\u7684 sendgrid \u5e10\u6237\uff0c\u4f46\u662f\u5f53\u6211\u8fd0\u884c\u6211\u7684\u51fd\u6570\u65f6\uff0c\u5b83\u4f1a\u5411\u6211\u663e\u793a\u4ee5\u4e0b\u9519\u8bef\uff0c\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u544a\u8bc9\u6211\u5982\u4f55\u89e3\u51b3\u5b83\u3002\u4e0b\u9762\u662f\u6211\u7684 golang \u51fd\u6570<\/p>\n<pre>func sendotpmail(otp string) (err error) {\n    from := mail.newemail(\"test\", \"[email&nbsp;protected]\")\n    subject := \"comfirmation mail\"\n    to := mail.newemail(\"puneet\", \"[email&nbsp;protected]\")\n    \/\/ plaintextcontent := \"\"\n    htmlcontent := \"your confirmation otp is = \" + otp\n    message := mail.newsingleemail(from, subject, to, \" \", htmlcontent) \/\/ (\"\" = plaintextcontent)\n    client := sendgrid.newsendclient(\"api_key\")\n    response, err := client.send(message)\n    fmt.println(response)\n    fmt.println(err)\n    return err\n}<\/pre>\n<p>\u4f5c\u4e3a\u54cd\u5e94\uff0c\u5b83\u5c06\u8fd4\u56de\u4ee5\u4e0b\u63a7\u5236\u53f0\u8f93\u51fa\uff1a<\/p>\n<pre>&amp;{403 {\"errors\":[{\"message\":\"The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https:\/\/sendgrid.com\/docs\/for-developers\/sending-email\/sender-identity\/ to see the Sender Identity requirements\",\"field\":\"from\",\"help\":null}]} map[Access-Control-Allow-Headers:[Authorization, Content-Type, On-behalf-of, x-sg-elas-acl] Access-Control-Allow-Methods:[POST] Access-Control-Allow-Origin:[https:\/\/sendgrid.api-docs.io] Access-Control-Max-Age:[600] Connection:[keep-alive] Content-Length:[281] Content-Type:[application\/json] Date:[Sat, 25 Apr 2020 12:56:25 GMT] Server:[nginx] X-No-Cors-Reason:[https:\/\/sendgrid.com\/docs\/Classroom\/Basics\/API\/cors.html]]}<\/pre>\n<p>\u6211\u4e5f\u5728 2019 \u5e74\u5b9e\u73b0\u4e86\u540c\u6837\u7684\u529f\u80fd\uff0c\u7136\u540e\u5b83\u53ef\u4ee5\u5de5\u4f5c\uff0c\u4f46\u73b0\u5728\u6211\u60f3\u66f4\u6539\u5b83\uff0c\u7136\u540e\u8fd9\u5411\u6211\u663e\u793a\u4e86\u8fd9\u4e2a\u9519\u8bef\u3002\u8bf7\u5e2e\u6211\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u7531\u4e8e\u8fd9\u662f sendgrid \u521b\u5efa\u7684\u65b0\u8bbe\u7f6e\uff0c\u65e8\u5728\u4fdd\u62a4\u60a8\u7684\u53d1\u9001\u58f0\u8a89\u5e76\u7ef4\u62a4\u5408\u6cd5\u7684\u53d1\u9001\u884c\u4e3a\uff0c\u56e0\u6b64\u5b83\u4eec\u8981\u6c42\u5ba2\u6237\u9a8c\u8bc1\u5176\u53d1\u4ef6\u4eba\u8eab\u4efd\u3002\u7531\u4e8e\u8fd9\u4e9b\u65e7\u7684 sendgrid \u5e10\u6237\u4e0d\u4f1a\u53d7\u5230\u5f71\u54cd\uff0c\u56e0\u6b64 2020 \u5e74 4 \u6708 6 \u65e5\u4e4b\u540e\u521b\u5efa\u7684\u5e10\u6237\u5c06\u80fd\u591f\u8fdb\u884c\u53d1\u4ef6\u4eba\u9a8c\u8bc1\u3002<\/p>\n<p>\u67e5\u770b\u6b64\u6587\u6863\u4ee5\u83b7\u53d6\u4fe1\u606f &#8211; <\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300agolang \u4e2d\u4e0e\u5df2\u9a8c\u8bc1\u7684\u53d1\u4ef6\u4eba\u8eab\u4efd\u4e0d\u5339\u914d\u9519\u8bef\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207724","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207724"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207724\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}