मैंने एक ऐसी स्क्रिप्ट लिखी है जो एक पाठ फ़ाइल को एक संदेश लिखती है और इसे ईमेल के रूप में भी भेजती है। सब कुछ ठीक हो जाता है, सिवाय इसके कि ईमेल अंततः एक पंक्ति में दिखाई देता है।पायथन के smtplib का उपयोग करके भेजे गए ई-मेल में लाइन ब्रेक कैसे प्राप्त करें?
मैं \n
द्वारा लाइन ब्रेक जोड़ता हूं और यह टेक्स्ट फ़ाइल के लिए काम करता है लेकिन ईमेल के लिए नहीं। क्या आप जानते हैं कि संभावित कारण क्या हो सकता है?
यहाँ मेरी कोड है:
import smtplib, sys
import traceback
def send_error(sender, recipient, headers, body):
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587
session = smtplib.SMTP('smtp.gmail.com', 587)
session.ehlo()
session.starttls()
session.ehlo
session.login(sender, 'my password')
send_it = session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
session.quit()
return send_it
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587
sender = '[email protected]'
recipient = '[email protected]yahoo.com'
subject = 'report'
body = "Dear Student, \n Please send your report\n Thank you for your attention"
open('student.txt', 'w').write(body)
headers = ["From: " + sender,
"Subject: " + subject,
"To: " + recipient,
"MIME-Version: 1.0",
"Content-Type: text/html"]
headers = "\r\n".join(headers)
send_error(sender, recipient, headers, body)
आपको बहुत बहुत धन्यवाद। '\ r \ n' मेरे लिए काम नहीं करता है लेकिन'
'करता है। –