3

我正在尝试创建一个 python 脚本来通过 smpt.gmail.com 发送电子邮件。我只被允许使用套接字。

目前,我已经获得了成功连接到服务器、声明 StartTLS 并将我的套接字包装在 SSL 中的脚本。但是,我在尝试向服务器进行身份验证时遇到了问题。

这是我的身份验证代码:

clientSocketSSL.send('AUTH LOGIN\r\n')
clientSocketSSL.send(base64.b64encode('USERNAME')+'\r\n')
clientSocketSSL.send(base64.b64encode('PASS')+'\r\n')

我得到的回应是

501 5.5.2 Cannot Decode response

那么 MAIL FROM 命令失败,因为我没有正确验证。

我觉得这是一个非常简单的解决方案,我只是错误地使用了身份验证登录吗?我已经找了两个小时了,但什么都没找到……

4

1 回答 1

0

它应该可以工作我自己用openssl尝试过:

OpenSSL> s_client -starttls smtp -connect smtp.gmail.com:587                                                 
CONNECTED(00000003)
depth=1 C = US, O = Google Inc, CN = Google Internet Authority
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDgDCCAumgAwIBAgIKO3T/ewAAAABoqDANBgkqhkiG9w0BAQUFADBGMQswCQYD
VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu
dGVybmV0IEF1dGhvcml0eTAeFw0xMjA5MTIxMTU3NTBaFw0xMzA2MDcxOTQzMjda
MGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N
b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRcwFQYDVQQDEw5zbXRw
LmdtYWlsLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAv0UvQmjW1y96
cOK6AdQVEYPRd3ZQ9UhxkKfuVaYS9riOESFkWxkz+b3Ts/EOA5SY8axkaJS7Qa/v
N7laztYY8tTkx9Ml+eCY4xh0fFq9z4/WWADGqTY5I0wvqjZr+jBuYGulK1fU4ZUS
QpuZMMO9x7Bmr5LVP9C5r2qnoqtMtJUCAwEAAaOCAVEwggFNMB0GA1UdJQQWMBQG
CCsGAQUFBwMBBggrBgEFBQcDAjAdBgNVHQ4EFgQUaCtARMZ9urIDfdpR6v1AkQsr
44owHwYDVR0jBBgwFoAUv8Aw6/VDET5nup6R+/xq2uNrEiQwWwYDVR0fBFQwUjBQ
oE6gTIZKaHR0cDovL3d3dy5nc3RhdGljLmNvbS9Hb29nbGVJbnRlcm5ldEF1dGhv
cml0eS9Hb29nbGVJbnRlcm5ldEF1dGhvcml0eS5jcmwwZgYIKwYBBQUHAQEEWjBY
MFYGCCsGAQUFBzAChkpodHRwOi8vd3d3LmdzdGF0aWMuY29tL0dvb2dsZUludGVy
bmV0QXV0aG9yaXR5L0dvb2dsZUludGVybmV0QXV0aG9yaXR5LmNydDAMBgNVHRMB
Af8EAjAAMBkGA1UdEQQSMBCCDnNtdHAuZ21haWwuY29tMA0GCSqGSIb3DQEBBQUA
A4GBADSkwmtEUhy/AhX2sIULT0Q5S9OlfKxbyE8hEc8nxls3jbk5yKZYd35Bzyy8
raoUPFuD3IH+zP/FGj5LPQirjnJLUvuFDsiM4eowPUthQad9SGWWdz6hCx8HpEUZ
1ssGnwb3HX34e9RH57v9LdtVUPdFYQsBJ36miGPylWk6r0xx
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com
issuer=/C=US/O=Google Inc/CN=Google Internet Authority
---
No client certificate CA names sent
---
SSL handshake has read 2304 bytes and written 383 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-RC4-SHA
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.1
    Cipher    : ECDHE-RSA-RC4-SHA
    Session-ID: 3A9E6D2BD679FD124B6772C91C74A5AFCEE7699A212D514FBC11710B684BDE31
    Session-ID-ctx: 
    Master-Key: D7B5B70090660B2359CFD8B82582033C16B569DEE6ACE1F6EB2CDD4E2042A613410B5E6DD07643664ABC33E8049547B8
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 100800 (seconds)
    TLS session ticket:
    0000 - 63 53 11 b3 92 0d 59 63-15 90 58 10 84 f2 f7 6a   cS....Yc..X....j
    0010 - e8 4b b0 a8 41 0a 73 0e-41 ee 3c a0 ab 91 df df   .K..A.s.A.<.....
    0020 - f0 24 b5 08 18 7d cc 56-05 9b 05 f4 e5 57 23 1b   .$...}.V.....W#.
    0030 - e0 00 33 e6 61 11 6b a2-9e 05 32 bb a3 99 8f 64   ..3.a.k...2....d
    0040 - 50 2c 6c 3a 5f 46 d1 53-2d 2a 3f 6a 8d cd c5 c8   P,l:_F.S-*?j....
    0050 - 4e 0a 15 63 04 e7 4e a0-01 51 79 93 38 3c de 62   N..c..N..Qy.8<.b
    0060 - 75 76 7a 0e 1c fc 98 0f-04 b5 b2 59 2a 1e c3 e5   uvz........Y*...
    0070 - aa d2 f6 2b 36 8c b8 97-77 77 9e 77 37 a7 ed 12   ...+6...ww.w7...
    0080 - d5 85 30 d2 e8 42 67 e8-84 97 0a f2 b6 95 fd 2f   ..0..Bg......../
    0090 - e7 f2 de 0e                                       ....

    Start Time: 1354229935
    Timeout   : 300 (sec)
    Verify return code: 20 (unable to get local issuer certificate)
---
250 ENHANCEDSTATUSCODES
ehlo
250-mx.google.com at your service, [188.79.92.35]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2
250 ENHANCEDSTATUSCODES
auth login
334 VXNlcm5hbWU6
MY_EMAIL_BASE64
334 UGFzc3dvcmQ6
MY_PASS_BASE64
235 2.7.0 Accepted
于 2012-11-29T23:08:14.780 回答