質問編集履歴

4

解決策を追記

2024/04/09 02:35

投稿

saya24
saya24

スコア227

test CHANGED
File without changes
test CHANGED
@@ -73,3 +73,34 @@
73
73
  smtp_obj.send_message(msg)
74
74
  smtp_obj.quit()
75
75
  ```
76
+ ### 結局 以下で解決
77
+ ```python
78
+ smtp_obj = smtplib.SMTP(SMTP, PORT)
79
+ # smtp_obj.starttls()
80
+ smtp_obj.login(LOGINID, PASSWORD)
81
+
82
+ cset ='iso-2022-jp'
83
+ msg = MIMEMultipart()
84
+ msg['Subject'] = p_subject
85
+ msg['To'] = TOADDRESS
86
+ msg['From'] = FROMADDRESS
87
+ body = MIMEText(p_body.encode(cset), 'plain', cset)
88
+ msg.preamble = 'This is a multi-part message in MIME format.'
89
+ msg.attach(body)
90
+
91
+ for entry in os.listdir(p_originpath):
92
+ filepath = os.path.join(p_originpath, entry)
93
+
94
+ if os.path.isfile(filepath):
95
+ with open(filepath, 'rb') as f:
96
+ content = f.read()
97
+ attachment = MIMEText(content, 'comma-separated-values', 'Shift-JIS')
98
+ filename_rfc2047 = Header(entry, 'iso-2022-jp', maxlinelen=55).encode().replace('\n', '')
99
+ attachment.set_param('name', filename_rfc2047)
100
+ attachment.add_header('Content-Disposition', 'attachment', filename=filename_rfc2047)
101
+
102
+ msg.attach(attachment)
103
+
104
+ smtp_obj.send_message(msg)
105
+ smtp_obj.quit()
106
+ ```

3

追記

2024/04/08 08:29

投稿

saya24
saya24

スコア227

test CHANGED
File without changes
test CHANGED
@@ -13,7 +13,10 @@
13
13
  OUTLOOKでの当該メールの表示状況になります。
14
14
  本来 添付ファイルは 各々PDF、PING、EXCELブックであり、ちゃんとしたファイル名を有しています。
15
15
  ![OUTLOOK添付ファイルの状況](https://ddjkaamml8q8x.cloudfront.net/questions/2024-04-08/0f3c9a2e-7162-4ae9-9dd4-715a5ab93257.png)
16
+
17
+
18
+ ### 該当のソースコード
16
- ``````Python
19
+ ``` python
17
20
  smtp_obj = smtplib.SMTP(SMTP, PORT)
18
21
  # smtp_obj.starttls()
19
22
  smtp_obj.login(LOGINID, PASSWORD)
@@ -38,3 +41,35 @@
38
41
 
39
42
  smtp_obj.send_message(msg)
40
43
  smtp_obj.quit()
44
+ ```
45
+
46
+
47
+ ### 過去記事参考になおしてみた...が相変わらずダメ
48
+ ```python
49
+ smtp_obj = smtplib.SMTP(SMTP, PORT)
50
+ # smtp_obj.starttls()
51
+ smtp_obj.login(LOGINID, PASSWORD)
52
+
53
+ body = p_body
54
+ msg = MIMEMultipart()
55
+ msg['Subject'] = p_subject
56
+ msg['To'] = TOADDRESS
57
+ msg['From'] = FROMADDRESS
58
+ msg.attach(MIMEText(body))
59
+
60
+ for entry in os.listdir(p_originpath):
61
+ filepath = os.path.join(p_originpath, entry)
62
+
63
+ if os.path.isfile(filepath):
64
+
65
+ with open(filepath, "rb") as f:
66
+ attachment = MIMEApplication(f.read())
67
+
68
+
69
+ attachment.set_param('name', entry) # outlook対応
70
+ attachment.add_header("Content-Disposition", "attachment", filename=('iso2022-jp', '', entry))
71
+ msg.attach(attachment)
72
+
73
+ smtp_obj.send_message(msg)
74
+ smtp_obj.quit()
75
+ ```

2

誤記

2024/04/08 07:55

投稿

saya24
saya24

スコア227

test CHANGED
File without changes
test CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  ### 発生している問題・エラーメッセージ
13
13
  OUTLOOKでの当該メールの表示状況になります。
14
- 本来ちゃんとした添付ファイル名で、各々PDF、PING、EXCELブックになります。
14
+ 本来 添付ファイルは 各々PDF、PING、EXCELブックであ、ちゃんとしたファイル名を有しています。
15
15
  ![OUTLOOK添付ファイルの状況](https://ddjkaamml8q8x.cloudfront.net/questions/2024-04-08/0f3c9a2e-7162-4ae9-9dd4-715a5ab93257.png)
16
16
  ``````Python
17
17
  smtp_obj = smtplib.SMTP(SMTP, PORT)

1

誤記

2024/04/08 07:43

投稿

saya24
saya24

スコア227

test CHANGED
File without changes
test CHANGED
@@ -38,4 +38,3 @@
38
38
 
39
39
  smtp_obj.send_message(msg)
40
40
  smtp_obj.quit()
41
- ```