質問編集履歴
1
コードとエラーの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1 +1,75 @@
|
|
1
1
|
Python3でメールを送信する方法を教えてください。自分でも調べてsmtplibを使い送信しようとしても接続の段階でエラーが出てしまいました
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
コード
|
6
|
+
|
7
|
+
```
|
8
|
+
|
9
|
+
from email.mime.text import MIMEText
|
10
|
+
|
11
|
+
message = MIMEText('TEST MAIL')
|
12
|
+
|
13
|
+
message['Subject'] = 'TEST'
|
14
|
+
|
15
|
+
message['From'] = '自分のメールアドレス'
|
16
|
+
|
17
|
+
message['To'] = '相手のメールアドレス'
|
18
|
+
|
19
|
+
import smtplib
|
20
|
+
|
21
|
+
sender = smtplib.SMTP_SSL('smtp.mail.outlook.com',587)
|
22
|
+
|
23
|
+
sender.login('自分のメールアドレス', 'パスワード')
|
24
|
+
|
25
|
+
sender.sendmail('自分のメールアドレス', '相手のメールアドレス', message.as_string())
|
26
|
+
|
27
|
+
sender.quit()
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
エラー
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
Traceback (most recent call last):
|
36
|
+
|
37
|
+
File "C:\Users\user\Desktop\send_mail.py", line 8, in <module>
|
38
|
+
|
39
|
+
sender = smtplib.SMTP_SSL('smtp.mail.outlook.com',587)
|
40
|
+
|
41
|
+
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 1030, in __init__
|
42
|
+
|
43
|
+
source_address)
|
44
|
+
|
45
|
+
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 251, in __init__
|
46
|
+
|
47
|
+
(code, msg) = self.connect(host, port)
|
48
|
+
|
49
|
+
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 336, in connect
|
50
|
+
|
51
|
+
self.sock = self._get_socket(host, port, self.timeout)
|
52
|
+
|
53
|
+
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 1038, in _get_socket
|
54
|
+
|
55
|
+
server_hostname=self._host)
|
56
|
+
|
57
|
+
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 401, in wrap_socket
|
58
|
+
|
59
|
+
_context=self, _session=session)
|
60
|
+
|
61
|
+
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 808, in __init__
|
62
|
+
|
63
|
+
self.do_handshake()
|
64
|
+
|
65
|
+
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 1061, in do_handshake
|
66
|
+
|
67
|
+
self._sslobj.do_handshake()
|
68
|
+
|
69
|
+
File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 683, in do_handshake
|
70
|
+
|
71
|
+
self._sslobj.do_handshake()
|
72
|
+
|
73
|
+
ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:748)
|
74
|
+
|
75
|
+
```
|