2014-03-06 181 views
2

我在將聯繫頁面添加到網頁時遇到問題。我正在使用Flask來做到這一點。 我不明白的部分是這樣的:燒瓶SMTP認證錯誤

app.config["MAIL_SERVER"] = "smtp.gmail.com" 
app.config["MAIL_PORT"] = 465 
app.config["MAIL_USE_SSL"] = True 
app.config["MAIL_USERNAME"] = '''[email protected]<script type="text/javascript"> 
/* <![CDATA[ */ 
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script"); 
l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s=''; 
r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r; 
s+=String.fromCharCode(c);}s=document.createTextNode(s); 
l.parentNode.replaceChild(s,l);}}catch(e){}})(); 
/* ]]> */ 
</script>]''' 

app.config["MAIL_PASSWORD"] = 'password' 

msg = Message(form.subject.data, sender='''[email protected]<script 
type="text/javascript"> 
/* <![CDATA[ */ 
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script"); 
l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s=''; 
r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r; 
s+=String.fromCharCode(c);}s=document.createTextNode(s); 
l.parentNode.replaceChild(s,l);}}catch(e){}})(); 
/* ]]> */ 
</script>', recipients=['[email protected]<script type="text/javascript"> 
/* <![CDATA[ */ 
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script"); 
l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s=''; 
r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r; 
s+=String.fromCharCode(c);}s=document.createTextNode(s); 
l.parentNode.replaceChild(s,l);}}catch(e){}})(); 
/* ]]> */ 
</script>]''') 

請解釋一下其中的電子郵件地址,我應該把在以下代碼的地方,我應該在哪裏加我的電子郵件ID?另一個應該是什麼。我沒有自己的域名。

app.config["MAIL_USERNAME"] = '''[email protected] 
app.config["MAIL_PASSWORD"] = 'password' 

msg = Message(form.subject.data, sender='''[email protected] 
recipients=['[email protected] . . 
+0

我指的是本教程http://code.tutsplus.com/tutorials/intro-to-flask-adding-a-contact-page--net- 28982 – user3182194

回答

2

該教程似乎有點過於複雜。不知道爲什麼你會需要所有的Javascript。下面是我什麼工作,我已經測試:

Gmail的配置設置應該是這樣的:

app.config['MAIL_SERVER']='smtp.gmail.com' 
app.config['MAIL_PORT'] = 465 
app.config['MAIL_USERNAME'] = '[email protected]' 
app.config['MAIL_PASSWORD'] = 'password' 
app.config['MAIL_USE_TLS'] = False 
app.config['MAIL_USE_SSL'] = True 

在上面的代碼,用您的實際Gmail地址更換app.config['MAIL_USERNAME']。密碼相同。使用此設置,電子郵件將從您的Gmail帳戶發送到接收方。以上所有信息均適用於發件人,即您的Gmail帳戶。

然後,發送電子郵件,只是下面的

msg = Message(subject,sender="[email protected]",recipients=['[email protected]','[email protected]']) 
msg.body = "test email" 
mail.send(msg) 

在上面的代碼,你想要的電子郵件發送給誰取代recipient秒。收件人是一個列表。因此,您可以根據需要輸入一個或多個電子郵件地址。

最後,利用上述2燒瓶郵件將從[email protected](也就是你)發送電子郵件至USER1 @ gmail.com,用戶2 @ gmail.com等(即接收器)

+0

非常感謝,你解釋清楚。這工作! – user3182194