2011-07-25 22 views
1
import poplib 

M = poplib.POP3_SSL('pop3.live.com', 995) #Connect to hotmail pop3 server 

try: 

    M.user(raw_input("username: ")) #Get the username from the standar input 
    M.pass_(raw_input("password: ")) #Get the password from the standar input 
except: 

    print "username or password incorrect" 
else: 

    print "Successful login" 

import smtplib 

msg = "warning" 

msg['From'] = "[email protected]" 

msg['To'] = "[email protected]" 

msg['Subject'] = "hello" 

s = smtplib.SMTP("smtp.live.com",25) 

s.sendmail("[email protected]", "[email protected]", msg.as_string()) 

s.quit() 

我意識到如何使用python登錄hotmail。如何使用python在hotmail中編寫郵件?

但我仍然無法在hotmail中發送電子郵件。

TypeError: 'str' object does not support item assignment This keep coming up. I have no idea why. 

有誰知道如何編寫下面的代碼。 Plz的幫助。我會很欣賞這一點。

+0

究竟是什麼樣的軟件,你的工作嗎? – pajton

回答

1

的問題就在這裏:

msg = "warning" 
msg['From'] = "[email protected]" 
msg['To'] = "[email protected]" 
msg['Subject'] = "hello" 

味精是一個str,你試圖把它像一本字典,並試圖將值分配給它。這是錯誤的。

你正在得到的錯誤是試圖說你不能給字符串中的索引位置賦值。

0

這是爲我好

import email 
import smtplib 

msg = email.message_from_string('warning') 
msg['From'] = "[email protected]" 
msg['To'] = "[email protected]" 
msg['Subject'] = "helOoooOo" 

s = smtplib.SMTP("smtp.live.com",587) 
s.ehlo() 
s.starttls() 
s.ehlo() 
s.login('[email protected]', 'pass') 


s.sendmail("[email protected]", "[email protected]", msg.as_string()) 

s.quit() 
+0

您能否提供更多信息,說明爲什麼您的代碼可以解決提問者問題? – morkro

相關問題