{"id":7090,"date":"2025-06-02T14:16:30","date_gmt":"2025-06-05T06:59:30","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7090"},"modified":"2025-06-05T14:16:30","modified_gmt":"2025-06-05T06:59:30","slug":"https-badgameshow-com-steven-220","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-220\/","title":{"rendered":"Swift 2025 \u6700\u65b0\u90f5\u4ef6\u767c\u9001\u6559\u5b78\uff1a\u7c21\u55ae\u5be6\u4f5c\u8207\u6700\u4f73\u5be6\u8e10 \ud83d\udce7"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u767c\u9001\u90f5\u4ef6, Swift \u90f5\u4ef6\u767c\u9001, MailCore, Swift \u6559\u5b78\"><\/p>\n<h1>Swift 2025 \u6700\u65b0\u90f5\u4ef6\u767c\u9001\u6559\u5b78\uff1a\u7c21\u55ae\u5be6\u4f5c\u8207\u6700\u4f73\u5be6\u8e10 \ud83d\udce7<\/h1>\n<p>Swift \u662f\u4e00\u7a2e\u975e\u5e38\u6d41\u884c\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u80fd\u5920\u8b93\u958b\u767c\u8005\u5feb\u901f\u958b\u767c\u51fa\u529f\u80fd\u5f37\u5927\u7684\u61c9\u7528\u7a0b\u5f0f\u3002\u5728 Swift \u4e2d\uff0c\u767c\u9001\u90f5\u4ef6\u662f\u4e00\u500b\u5e38\u898b\u7684\u9700\u6c42\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Swift \u548c\u6700\u65b0\u7684 MailCore \u6846\u67b6\u4f86\u767c\u9001\u90f5\u4ef6\uff0c\u63d0\u4f9b\u5b8c\u6574\u7684\u5be6\u4f5c\u7bc4\u4f8b\u4ee5\u53ca\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2>\u5b89\u88dd MailCore \u6846\u67b6<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88dd <strong>MailCore<\/strong> \u6846\u67b6\u3002MailCore \u662f\u4e00\u500b\u958b\u6e90\u6846\u67b6\uff0c\u65b9\u4fbf\u958b\u767c\u8005\u9032\u884c\u90f5\u4ef6\u7684\u767c\u9001\u548c\u63a5\u6536\u3002\u53ef\u4ee5\u4f7f\u7528 CocoaPods \u9032\u884c\u5b89\u88dd\uff0c\u8acb\u5728\u60a8\u7684 Podfile \u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>pod 'MailCore2'<\/code><\/pre>\n<p>\u7136\u5f8c\u904b\u884c <code>pod install<\/code> \u4ee5\u5b89\u88dd\u8a72\u6846\u67b6\u3002<\/p>\n<h2>\u4f7f\u7528 Swift \u767c\u9001\u90f5\u4ef6<\/h2>\n<p>\u5b89\u88dd\u5b8c MailCore \u6846\u67b6\u5f8c\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 Swift \u767c\u9001\u90f5\u4ef6\u4e86\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u5b8c\u6574\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>import MailCore\n\nlet smtpSession = MCOSMTPSession()\nsmtpSession.hostname = \"smtp.example.com\" \/\/ SMTP \u4f3a\u670d\u5668\u5730\u5740\nsmtpSession.username = \"username\" \/\/ \u60a8\u7684\u90f5\u4ef6\u5e33\u865f\nsmtpSession.password = \"password\" \/\/ \u60a8\u7684\u90f5\u4ef6\u5bc6\u78bc\nsmtpSession.port = 465 \/\/ SMTP \u7aef\u53e3\nsmtpSession.connectionType = .TLS \/\/ \u9023\u63a5\u985e\u578b\n\nlet builder = MCOMessageBuilder()\nbuilder.header.to = [MCOAddress(displayName: \"\u6536\u4ef6\u4eba\u59d3\u540d\", mailbox: \"recipient@example.com\")]\nbuilder.header.from = MCOAddress(displayName: \"\u767c\u4ef6\u4eba\u59d3\u540d\", mailbox: \"sender@example.com\")\nbuilder.header.subject = \"\u4e3b\u984c: \u60a8\u597d\uff01\"\nbuilder.htmlBody = \"<p><b>\u60a8\u597d\uff01<\/b><br>\u9019\u662f\u4e00\u5c01\u6e2c\u8a66\u90f5\u4ef6\u3002<\/p>\"\n\nlet rfc822Data = builder.data()\nlet sendOperation = smtpSession.sendOperation(with: rfc822Data)\nsendOperation.start { (error) -> Void in\n    if let error = error {\n        print(\"\u767c\u9001\u90f5\u4ef6\u6642\u767c\u751f\u932f\u8aa4: \\(error.localizedDescription)\")\n    } else {\n        print(\"\u90f5\u4ef6\u6210\u529f\u767c\u9001\uff01\")\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u5efa\u7acb\u4e86\u4e00\u500b SMTP \u9023\u63a5\uff0c\u4f7f\u7528 <strong>MCOMessageBuilder<\/strong> \u4f86\u5efa\u7acb\u90f5\u4ef6\u5167\u5bb9\uff0c\u7136\u5f8c\u5229\u7528 <strong>MCOSMTPSession<\/strong> \u7684 <strong>sendOperation<\/strong> \u65b9\u6cd5\u4f86\u767c\u9001\u90f5\u4ef6\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u767c\u9001\u90f5\u4ef6\u6642\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u932f\u8aa4\uff0c\u4ee5\u4e0b\u662f\u5e7e\u500b\u6392\u9664\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li><strong>SMTP \u9023\u63a5\u5931\u6557\uff1a<\/strong>\u8acb\u6aa2\u67e5 SMTP \u4f3a\u670d\u5668\u5730\u5740\u3001\u7aef\u53e3\u53ca\u9023\u63a5\u985e\u578b\u662f\u5426\u6b63\u78ba\u3002<\/li>\n<li><strong>\u8a8d\u8b49\u5931\u6557\uff1a<\/strong>\u78ba\u8a8d\u60a8\u7684\u7528\u6236\u540d\u548c\u5bc6\u78bc\u6b63\u78ba\u7121\u8aa4\u3002<\/li>\n<li><strong>\u90f5\u4ef6\u683c\u5f0f\u932f\u8aa4\uff1a<\/strong>\u78ba\u4fdd\u90f5\u4ef6\u7684\u6536\u4ef6\u4eba\u53ca\u767c\u4ef6\u4eba\u683c\u5f0f\u6b63\u78ba\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u7c21\u55ae\u7684\u90f5\u4ef6\u767c\u9001\u5916\uff0c\u60a8\u9084\u53ef\u4ee5\u4f7f\u7528 MailCore \u9032\u884c\u66f4\u9ad8\u7d1a\u7684\u529f\u80fd\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u767c\u9001\u5305\u542b\u9644\u4ef6\u7684\u90f5\u4ef6\u3002<\/li>\n<li>\u8a2d\u8a08\u8207\u767c\u9001 HTML \u683c\u5f0f\u7684\u90f5\u4ef6\u3002<\/li>\n<li>\u8a2d\u7f6e\u90f5\u4ef6\u7684\u512a\u5148\u7d1a\u8207\u91cd\u8981\u6027\u3002<\/li>\n<\/ul>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 Swift \u548c MailCore \u6846\u67b6\u767c\u9001\u90f5\u4ef6\u3002\u5f9e\u5b89\u88dd\u6846\u67b6\u5230\u5be6\u4f5c\u7bc4\u4f8b\uff0c\u9019\u4e9b\u6b65\u9a5f\u90fd\u80fd\u5e6b\u52a9\u60a8\u5feb\u901f\u4e0a\u624b\u90f5\u4ef6\u767c\u9001\u529f\u80fd\u3002\u96a8\u8457 Swift \u7684\u6301\u7e8c\u767c\u5c55\uff0c\u672a\u4f86\u9084\u6703\u6709\u66f4\u591a\u66f4\u65b0\u8207\u6539\u9032\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u7c21\u55ae\u7684\u767c\u9001\u90f5\u4ef6\u65b9\u6cd5-\ud83d\udce7_1675402223.172132.webp\" alt=\"Swift \u7c21\u55ae\u7684\u767c\u9001\u90f5\u4ef6\u65b9\u6cd5 \ud83d\udce7\" title=\"Swift \u90f5\u4ef6\u767c\u9001\u3001Swift \u65b9\u6cd5\u3001Swift \u767c\u9001\u90f5\u4ef6\u3001Swift \u7a0b\u5f0f\u8a9e\u6cd5\u3001Swift \u529f\u80fd\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. \u5982\u4f55\u767c\u9001\u5e36\u6709\u9644\u4ef6\u7684\u90f5\u4ef6\uff1f<\/h3>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 <strong>MCOAttachment<\/strong> \u4f86\u6dfb\u52a0\u9644\u4ef6\uff0c\u4e26\u5728 <strong>MCOMessageBuilder<\/strong> \u4e2d\u4f7f\u7528 <code>addAttachment<\/code> \u65b9\u6cd5\u4f86\u9644\u52a0\u6587\u4ef6\u3002<\/p>\n<h3>2. \u4f7f\u7528 MailCore \u767c\u9001\u90f5\u4ef6\u9700\u8981\u8003\u616e\u54ea\u4e9b\u5b89\u5168\u6027\u554f\u984c\uff1f<\/h3>\n<p>\u5efa\u8b70\u4f7f\u7528 TLS \u9023\u63a5\u4f86\u78ba\u4fdd\u90f5\u4ef6\u50b3\u8f38\u7684\u5b89\u5168\u6027\uff0c\u4e26\u5b9a\u671f\u66f4\u65b0\u60a8\u7684\u90f5\u4ef6\u5e33\u865f\u5bc6\u78bc\u3002<\/p>\n<h3>3. MailCore \u662f\u5426\u652f\u63f4\u591a\u8a9e\u8a00\u90f5\u4ef6\u767c\u9001\uff1f<\/h3>\n<p>\u662f\u7684\uff0cMailCore \u652f\u63f4 Unicode\uff0c\u53ef\u7528\u65bc\u767c\u9001\u591a\u8a9e\u8a00\u90f5\u4ef6\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2Swift\u4e2d\u7c21\u55ae\u7684\u767c\u9001\u90f5\u4ef6\u65b9\u6cd5\uff0c\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684methods()\u51fd\u6578\u4f86\u767c\u9001\u90f5\u4ef6\uff0c\u8b93\u4f60\u53ef\u4ee5\u8f15\u9b06\u5730\u767c\u9001\u90f5\u4ef6\uff0c\u8b93\u4f60\u7684\u5de5\u4f5c\u66f4\u52a0\u9806\u5229\u3002<\/p>\n","protected":false},"author":1,"featured_media":7089,"comment_status":"open","ping_status":"closed","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":[174,5],"tags":[173,9],"class_list":["post-7090","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u7c21\u55ae\u7684\u767c\u9001\u90f5\u4ef6\u65b9\u6cd5-\ud83d\udce7_1675402223.172132.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Qm","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7090","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=7090"}],"version-history":[{"count":4,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7090\/revisions"}],"predecessor-version":[{"id":13302,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7090\/revisions\/13302"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7089"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}