{"id":15061,"date":"2021-06-11T18:00:22","date_gmt":"2021-06-11T09:00:22","guid":{"rendered":"https:\/\/itport.cloud\/?p=15061"},"modified":"2021-06-11T18:05:54","modified_gmt":"2021-06-11T09:05:54","slug":"post-15061","status":"publish","type":"post","link":"https:\/\/itport.cloud\/?p=15061","title":{"rendered":"\uff08\u7b2c\uff12\u56de\uff09GmailAPI\u3092\u4f7f\u7528\u3057\u305f\u30e1\u30fc\u30eb\u306e\u81ea\u52d5\u4f5c\u6210"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"e79baee6aca1-1\">\u76ee\u6b21<\/h2>\n\n\n\n<p><a href=\"#A-1\">\u632f\u308a\u8fd4\u308a<\/a><br><a href=\"#A-2\">\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><br><a href=\"#A-3\">\u30d1\u30b9\u30ef\u30fc\u30c9\u5727\u7e2e\u51e6\u7406\u3092\u524d\u56de\u306e\u30b3\u30fc\u30c9\u306b\u30de\u30fc\u30b8<\/a><br><a href=\"#A-4\">\u307e\u3068\u3081<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"A-1\"> \u632f\u308a\u8fd4\u308a <\/h2>\n\n\n\n<p>\u524d\u56de\u306fGmailAPI\u3092\u4e0b\u66f8\u304d\u3092\u4f5c\u6210\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<br>\u4eca\u56de\u306f\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3092\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u3057\u3001\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3057\u305f\u4e0b\u66f8\u304d\u3068\u305d\u306e\u5727\u7e2e\u3059\u308b\u969b\u306b\u4f7f\u7528\u3057\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u8a18\u8f09\u3055\u308c\u305f\u4e0b\u66f8\u304d\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"A-2\">\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n\n\n\n<p>Python\u306e\u6a19\u6e96\u95a2\u6570\u3067zip\u306e\u5727\u7e2e\u3084\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u30d5\u30a1\u30a4\u30eb\u306e\u89e3\u51cd\u306f\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u304c\u3067\u304d\u307e\u305b\u3093\u3002<br>\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u3059\u308b\u305f\u3081\u306b\u306f\u300cpyminizip\u300d\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\uff11\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u5b9f\u65bd\u3002<br>Visual Studio Code\u306e\u30bf\u30fc\u30df\u30ca\u30eb\u3092\u958b\u304d\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install pyminizip\n<\/pre><\/div>\n\n\n<p>\uff12\u3001\u52d5\u4f5c\u306e\u78ba\u8a8d\u3092\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# \u300cpyminizip\u300d\u306eimport\nimport pyminizip\n\ndef main():\n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u3092\u5b9f\u65bd\n    pyminizip.compress(\"C:\/GmaiDraft\/test.txt\", \"\", \"C:\/GmaiDraft\/test.zip\", \"abc123\", 1)\n\nif __name__ == '__main__':\n    main()\n<\/pre><\/div>\n\n\n<p>\u203b\u5f15\u6570\u306f\u4e0b\u8a18\u306e\u901a\u308a\u3067\u3059\u3002<br>\u7b2c\uff11\uff1a\u5727\u7e2e\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u3092\u6307\u5b9a\uff08\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u542b\u3081\u308b\uff09<br>\u7b2c\uff12\uff1a\u5727\u7e2e\u30d5\u30a9\u30eb\u30c0\u5185\u306e\u968e\u5c64\u3092\u6307\u5b9a<br>\u7b2c\uff13\uff1a \u51fa\u529b\u3059\u308b\u969b\u306e\u30d1\u30b9\u3092\u6307\u5b9a \uff08\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u542b\u3081\u308b\uff09 <br>\u7b2c\uff14\uff1a \u5727\u7e2e\u3059\u308b\u969b\u306e\u30d1\u30b9\u30ef\u30fc\u30c9<br>\u7b2c\uff15\uff1a0\uff5e9\u3067\u5727\u7e2e\u7387\u3092\u6307\u5b9a\u3000<br>\u21920\u306f\u7121\u5727\u7e2e\u3067\u6570\u5024\u304c\u5927\u304d\u304f\u306a\u308c\u3070\u306a\u308b\u307b\u3069\u306b\u5727\u7e2e\u7387\u304c\u9ad8\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\uff13\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport pyminizip\nimport random\n\ndef create_password():\n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u6841\u6570\n    passwordLength = 8\n \n    password = ''    \n \n    #  \u30d1\u30b9\u30ef\u30fc\u30c9\u306b\u4f7f\u3046\u6587\u5b57\u5217\n    passwordPattern = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'\n \n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u751f\u6210\n    for i in range(0, passwordLength):\n        password = password + random.sample(passwordPattern, 1)&#x5B;0]\n\n    return password\n\ndef main():\n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u751f\u6210\n    password = create_password()\n\n    # \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u8868\u793a\n    print(password)\n\n    # \u5727\u7e2e\u306e\u5b9f\u884c\n    pyminizip.compress(\"C:\/GmaiDraft\/test.txt\", \"\", \"C:\/GmaiDraft\/test.zip\", password, 1)\n\nif __name__ == '__main__':\n    main()\n<\/pre><\/div>\n\n\n<p>\uff14\u3001\u5b9f\u884c\u3057\u307e\u3059\u3002\u4e0b\u8a18\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br>\u30d1\u30b9\u30ef\u30fc\u30c9\uff1a3MpzD3vH<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"95\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/4-1024x95.png\" alt=\"\" class=\"wp-image-15097\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/4-1024x95.png 1024w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/4-300x28.png 300w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/4-768x71.png 768w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/4-450x42.png 450w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/4-900x84.png 900w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/4.png 1096w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\uff15\u3001\u5727\u7e2e\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"239\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/1-1.png\" alt=\"\" class=\"wp-image-15093\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/1-1.png 975w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/1-1-300x74.png 300w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/1-1-768x188.png 768w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/1-1-450x110.png 450w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/1-1-900x221.png 900w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/figure>\n\n\n\n<p>\uff16\u3001\u5148\u307b\u3069\u51fa\u529b\u3055\u308c\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\u300c3MpzD3vH\u300d\u3092\u5165\u529b\u3057\u3066\u89e3\u51cd\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/2.png\" alt=\"\" class=\"wp-image-15094\" width=\"628\" height=\"487\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/2.png 628w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/2-300x233.png 300w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/2-413x320.png 413w\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" \/><\/figure>\n\n\n\n<p>\uff17\u3001\u554f\u984c\u306a\u304f\u89e3\u51cd\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"915\" height=\"161\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/3.png\" alt=\"\" class=\"wp-image-15095\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/3.png 915w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/3-300x53.png 300w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/3-768x135.png 768w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/3-450x79.png 450w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/3-900x158.png 900w\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"A-3\">\u30d1\u30b9\u30ef\u30fc\u30c9\u5727\u7e2e\u51e6\u7406\u3092\u524d\u56de\u306e\u30b3\u30fc\u30c9\u306b\u30de\u30fc\u30b8<\/h2>\n\n\n\n<p>\uff11\u3001\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8ffd\u52a0<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# \u30e1\u30fc\u30eb\u306e\u672c\u6587\u306e\u5185\u5bb9\u3092\u683c\u7d0d\u3059\u308b\u30af\u30e9\u30b9\nfrom email.mime.multipart import MIMEMultipart\n# \u30e1\u30fc\u30eb\u306e\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3059\u308b\u30af\u30e9\u30b9\nfrom email.mime.application import MIMEApplication\n# \u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u53d6\u5f97\nfrom os.path import basename\n# \u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\nimport pyminizip\n# \u30d1\u30b9\u30ef\u30fc\u30c9\u751f\u6210\u306e\u4e71\u6570\u751f\u6210\u306b\u4f7f\u7528\nimport random\n\n<\/pre><\/div>\n\n\n<p>\uff12\u3001\u30e1\u30fc\u30eb\u306e\u672c\u6587\u4f5c\u6210\u3059\u308b\u95a2\u6570\u3092\u7de8\u96c6<br>\u203b\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u4ed8\u304d\u306e\u95a2\u6570\u3092\u30d1\u30b9\u30ef\u30fc\u30c9\u8a18\u8f09\u306e\u30e1\u30fc\u30eb\u306e\u95a2\u6570\u3092\u5206\u3051\u3066\u3044\u307e\u3059\u3002<br>\u3000 <br>\u3000\u25a0\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u4ed8\u304d\u30e1\u30fc\u30eb\u672c\u6587\u4f5c\u6210\u95a2\u6570 <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# \u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u306e\u30e1\u30fc\u30eb\u672c\u6587\u306e\u4f5c\u6210\ndef create_message_compress(subject, message_text, password):\n    # \u30e1\u30fc\u30eb\u306e\u5185\u5bb9\u3092\u683c\u7d0d\n    message = MIMEMultipart()    \n    message&#x5B;'subject'] = subject\n    message.attach(MIMEText(message_text))\n    \n    # \u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\n    pyminizip.compress(\"C:\/GmaiDraft\/test.txt\", \"\", \"C:\/GmaiDraft\/test.zip\", password, 1)    \n\n    path = \"C:\/GmaiDraft\/test.zip\"\n    with open(path, \"rb\") as f:\n        part = MIMEApplication(\n            f.read(),\n            Name=basename(path)\n        )\n    part&#x5B;'Content-Disposition'] = 'attachment; filename=\"%s\"' % basename(path)\n    message.attach(part)\n\n    encode_message = base64.urlsafe_b64encode(message.as_bytes())\n    return {'raw': encode_message.decode()}\n\n<\/pre><\/div>\n\n\n<p>\u3000\u25a0\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u7121\u3057\u306e\u30e1\u30fc\u30eb\u672c\u6587\u4f5c\u6210\u95a2\u6570<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# \u30d1\u30b9\u30ef\u30fc\u30c9\u8a18\u8f09\u306e\u30e1\u30fc\u30eb\u672c\u6587\u306e\u4f5c\u6210\ndef create_message_password(subject, password):\n    # \u30e1\u30fc\u30eb\u306e\u5185\u5bb9\u3092\u683c\u7d0d\n    message = MIMEMultipart()    \n    message&#x5B;'subject'] = subject\n    message.attach(MIMEText(password))\n    \n    encode_message = base64.urlsafe_b64encode(message.as_bytes())\n    return {'raw': encode_message.decode()}\n<\/pre><\/div>\n\n\n<p>\uff13\u3001\u30e1\u30a4\u30f3\u95a2\u6570\u306e\u4fee\u6b63<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# \u30e1\u30a4\u30f3\u306e\u51e6\u7406\ndef main():\n    # Google\u8a8d\u8a3c\u306e\u51e6\u7406\n    creds = None\n    if os.path.exists('token.pickle'):\n        with open('token.pickle', 'rb') as token:\n            creds = pickle.load(token)\n    if not creds or not creds.valid:\n        if creds and creds.expired and creds.refresh_token:\n            creds.refresh(Request())\n        else:\n            flow = InstalledAppFlow.from_client_secrets_file(\n                'credentials.json', SCOPES)\n            creds = flow.run_local_server()\n        with open('token.pickle', 'wb') as token:\n            pickle.dump(creds, token)\n\n    # GmailAPI\u3092\u5b9f\u884c\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u4f5c\u6210\n    service = build('gmail', 'v1', credentials=creds)\n\n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u4f5c\u6210\n    password = create_password()\n\n    # \u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u4ed8\u304d\u4e0b\u66f8\u304d\u30e1\u30fc\u30eb\u306e\u4f5c\u6210\n    subject = '\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u30e1\u30fc\u30eb'\n    message_text = '\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3057\u3066\u3044\u307e\u3059'\n\n    message = create_message_compress(subject, message_text, password)\n\n    # \u4e0b\u66f8\u304d\u4f5c\u6210\n    create_draft(service, 'me', message)\n\n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u8a18\u8f09\u3057\u305f\u4e0b\u66f8\u304d\u30e1\u30fc\u30eb\u306e\u4f5c\u6210\n    subject = '\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u30e1\u30fc\u30eb'\n\n    message = create_message_password(subject, password)\n    \n    # \u4e0b\u66f8\u304d\u4f5c\u6210\n    create_draft(service, 'me', message)\n<\/pre><\/div>\n\n\n<p>\uff14\u3001\u53c2\u8003\u307e\u3067\u306b\u30b3\u30fc\u30c9\u5168\u4f53\u3092\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom __future__ import print_function\nimport pickle\nimport os.path\nfrom googleapiclient.discovery import build\nfrom google_auth_oauthlib.flow import InstalledAppFlow\nfrom google.auth.transport.requests import Request\n# \u30af\u30a4\u30c3\u30af\u30b9\u30bf\u30fc\u30c8\u306b\u8db3\u308a\u306a\u3044\u9805\u76ee\u306eimport\nimport base64\nfrom email.mime.text import MIMEText\nfrom apiclient import errors\n# \u4eca\u56de\u8ffd\u52a0\u3057\u305fimport\n# \u30e1\u30fc\u30eb\u306e\u672c\u6587\u306e\u5185\u5bb9\u3092\u683c\u7d0d\u3059\u308b\u30af\u30e9\u30b9\nfrom email.mime.multipart import MIMEMultipart\n# \u30e1\u30fc\u30eb\u306e\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u683c\u7d0d\u3059\u308b\u30af\u30e9\u30b9\nfrom email.mime.application import MIMEApplication\n# \u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u53d6\u5f97\nfrom os.path import basename\n# \u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u3059\u308b\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\nimport pyminizip\n# \u30d1\u30b9\u30ef\u30fc\u30c9\u751f\u6210\u306e\u4e71\u6570\u751f\u6210\u306b\u4f7f\u7528\nimport random\n\n# Gmail API\u306e\u30b9\u30b3\u30fc\u30d7\u3092\u8a2d\u5b9a\nSCOPES = &#x5B;'https:\/\/www.googleapis.com\/auth\/gmail.modify']\n\n# Gmail\u306e\u4e0b\u66f8\u304d\u4f5c\u6210 \ndef create_draft(service, user_id, message_body):\n  try:\n    message = {'message': message_body}\n    draft = service.users().drafts().create(userId=user_id, body=message).execute()\n\n    print ('Draft id: %s\\nDraft message: %s' % (draft&#x5B;'id'], draft&#x5B;'message']))\n\n    return draft\n  except errors.HttpError as error:\n    print ('\u30a8\u30e9\u30fc: %s' % error)\n    return None\n\n# \u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u306e\u30e1\u30fc\u30eb\u672c\u6587\u306e\u4f5c\u6210\ndef create_message_compress(subject, message_text, password):\n    # \u30e1\u30fc\u30eb\u306e\u5185\u5bb9\u3092\u683c\u7d0d\n    message = MIMEMultipart()    \n    message&#x5B;'subject'] = subject\n    message.attach(MIMEText(message_text))\n    \n    # \u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\n    pyminizip.compress(\"C:\/GmaiDraft\/test.txt\", \"\", \"C:\/GmaiDraft\/test.zip\", password, 1)    \n\n    path = \"C:\/GmaiDraft\/test.zip\"\n    with open(path, \"rb\") as f:\n        part = MIMEApplication(\n            f.read(),\n            Name=basename(path)\n        )\n    part&#x5B;'Content-Disposition'] = 'attachment; filename=\"%s\"' % basename(path)\n    message.attach(part)\n\n    encode_message = base64.urlsafe_b64encode(message.as_bytes())\n    return {'raw': encode_message.decode()}\n\n# \u30d1\u30b9\u30ef\u30fc\u30c9\u8a18\u8f09\u306e\u30e1\u30fc\u30eb\u672c\u6587\u306e\u4f5c\u6210\ndef create_message_password(subject, password):\n    # \u30e1\u30fc\u30eb\u306e\u5185\u5bb9\u3092\u683c\u7d0d\n    message = MIMEMultipart()    \n    message&#x5B;'subject'] = subject\n    message.attach(MIMEText(password))\n    \n    encode_message = base64.urlsafe_b64encode(message.as_bytes())\n    return {'raw': encode_message.decode()}\n\n# \u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u4f5c\u6210\ndef create_password():\n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u6841\u6570\n    passwordLength = 8\n \n    # \u30d1\u30b9\u30ef\u30fc\u30c9\n    password = ''\n \n    #  \u30d1\u30b9\u30ef\u30fc\u30c9\u306b\u4f7f\u3046\u6587\u5b57\u5217\n    passwordPattern = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'\n \n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u751f\u6210\u30eb\u30fc\u30d7\n    for i in range(0, passwordLength):\n        password = password + random.sample(passwordPattern, 1)&#x5B;0]\n\n    return password\n\n# \u30e1\u30a4\u30f3\u306e\u51e6\u7406\ndef main():\n    # Google\u8a8d\u8a3c\u306e\u51e6\u7406\n    creds = None\n    if os.path.exists('token.pickle'):\n        with open('token.pickle', 'rb') as token:\n            creds = pickle.load(token)\n    if not creds or not creds.valid:\n        if creds and creds.expired and creds.refresh_token:\n            creds.refresh(Request())\n        else:\n            flow = InstalledAppFlow.from_client_secrets_file(\n                'credentials.json', SCOPES)\n            creds = flow.run_local_server()\n        with open('token.pickle', 'wb') as token:\n            pickle.dump(creds, token)\n\n    # GmailAPI\u3092\u5b9f\u884c\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u4f5c\u6210\n    service = build('gmail', 'v1', credentials=creds)\n\n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u4f5c\u6210\n    password = create_password()\n\n    # \u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u4ed8\u304d\u4e0b\u66f8\u304d\u30e1\u30fc\u30eb\u306e\u4f5c\u6210\n    subject = '\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u30e1\u30fc\u30eb'\n    message_text = '\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3057\u3066\u3044\u307e\u3059'\n\n    message = create_message_compress(subject, message_text, password)\n\n    # \u4e0b\u66f8\u304d\u4f5c\u6210\n    create_draft(service, 'me', message)\n\n    # \u30d1\u30b9\u30ef\u30fc\u30c9\u8a18\u8f09\u3057\u305f\u4e0b\u66f8\u304d\u30e1\u30fc\u30eb\u306e\u4f5c\u6210\n    subject = '\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u30e1\u30fc\u30eb'\n\n    message = create_message_password(subject, password)\n    \n    # \u4e0b\u66f8\u304d\u4f5c\u6210\n    create_draft(service, 'me', message)\n\nif __name__ == '__main__':\n    main()\n<\/pre><\/div>\n\n\n<p>\uff15\u3001\u5b9f\u969b\u306b\u5b9f\u884c\u3057\u3066\u52d5\u4f5c\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"487\" src=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/5-1-1024x487.png\" alt=\"\" class=\"wp-image-15121\" srcset=\"https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/5-1-1024x487.png 1024w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/5-1-300x143.png 300w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/5-1-768x365.png 768w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/5-1-450x214.png 450w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/5-1-900x428.png 900w, https:\/\/itport.cloud\/wp-content\/uploads\/2021\/06\/5-1.png 1372w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\uff16\u3001\uff12\u4ef6\u306e\u4e0b\u66f8\u304d\u304c\u4f5c\u6210\u3055\u308c\u3066\u60f3\u5b9a\u901a\u308a\u306e\u5185\u5bb9\u3067\u4f5c\u6210\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u304c\u6dfb\u4ed8\u3055\u308c\u3066\u3044\u308b\u4e0b\u66f8\u304d<\/li><li>\u5727\u7e2e\u3059\u308b\u969b\u306b\u8a2d\u5b9a\u3057\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u8a18\u8f09\u3055\u308c\u3066\u3044\u308b\u30e1\u30fc\u30eb<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"A-4\">\u307e\u3068\u3081 <\/h2>\n\n\n\n<p>\u4eca\u56de\u3001\u60f3\u5b9a\u901a\u308a\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u4f5c\u6210\u3067\u304d\u307e\u3057\u305f\u3002<br>\u3067\u3059\u304c\u3001\u307e\u3060\uff11\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u3057\u304b\u6307\u5b9a\u3067\u304d\u306a\u304b\u3063\u305f\u308a\u3001\u30d1\u30b9\u304c\u56fa\u5b9a\u306e\u30d1\u30b9\u306e\u307f\u306e\u5bfe\u5fdc\u3068\u306a\u3063\u3066\u3044\u308b\u70ba\u3001\u6b21\u56de\u306f\u305d\u3046\u3044\u3063\u305f\u90e8\u5206\u3092\u6c4e\u7528\u7684\u306b\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u4fee\u6b63\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br><\/p>\n","protected":false},"excerpt":{"rendered":"\u76ee\u6b21 \u632f\u308a\u8fd4\u308a\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u30d1\u30b9\u30ef\u30fc\u30c9\u5727\u7e2e\u51e6\u7406\u3092\u524d\u56de\u306e\u30b3\u30fc\u30c9\u306b\u30de\u30fc\u30b8\u307e\u3068\u3081 \u632f\u308a\u8fd4\u308a \u524d\u56de\u306fGmailAPI\u3092\u4e0b\u66f8\u304d\u3092\u4f5c\u6210\u3059\u308b\u3068\u3053\u308d\u307e\u3067\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002\u4eca\u56de\u306f\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u3092\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u3057\u3001\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6dfb\u4ed8\u3057\u305f\u4e0b\u66f8\u304d\u3068\u305d\u306e\u5727\u7e2e\u3059\u308b\u969b\u306b\u4f7f\u7528\u3057\u305f\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u8a18\u8f09\u3055\u308c\u305f\u4e0b\u66f8\u304d\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 \u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb Python\u306e\u6a19\u6e96\u95a2\u6570\u3067zip\u306e\u5727\u7e2e\u3084\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u30d5\u30a1\u30a4\u30eb\u306e\u89e3\u51cd\u306f\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u304c\u3067\u304d\u307e\u305b\u3093\u3002\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u5727\u7e2e\u3059\u308b\u305f\u3081\u306b\u306f\u300cpyminizip\u300d\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \uff11\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u5b9f\u65bd\u3002Visual Studio Code\u306e\u30bf\u30fc\u30df\u30ca\u30eb\u3092\u958b\u304d\u4ee5\u4e0b\u306e\u30b3\u30fc&hellip;","protected":false},"author":1,"featured_media":15246,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105,106],"tags":[104],"class_list":{"0":"post-15061","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-gmail","8":"category-python","9":"tag-season34"},"_links":{"self":[{"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/posts\/15061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15061"}],"version-history":[{"count":8,"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/posts\/15061\/revisions"}],"predecessor-version":[{"id":15248,"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/posts\/15061\/revisions\/15248"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=\/wp\/v2\/media\/15246"}],"wp:attachment":[{"href":"https:\/\/itport.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itport.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}