SMTPLIB 中的换行符 Python 3
Line breaks in SMTPLIB Python 3
我正在尝试制作一个发送电子邮件的脚本。但是怎么换行呢?我尝试了以下方法:
将msg = MIMEText(msginp)
更改为msg=MIMEText(msginp,_subtype='plain',_charset='windows-1255')
NOTE: msginp is a input (msginp = input('Body? ')
)
有人知道如何换行吗?喜欢键盘上的 enter
键吗?
我的代码是:
import smtplib
from email.mime.text import MIMEText
import getpass
smtpserverinp = input('What SMTP server are you using? (Look here for more information. https://sites.google.com/view/smtpserver) ')
usern = input('What is your email adderess? ')
p = getpass.getpass(prompt='What is your password? (You will not see that you are typing because it is a password) ')
subjectss = input('Subject? ')
msginp = input('Body? ')
toaddr = input('To who do you want to send it to? ')
msg = MIMEText(msginp)
msg['Subject'] = subjectss
msg['From'] = usern
msg['To'] = toaddr
s = smtplib.SMTP(smtpserverinp, 587)
s.starttls()
s.login(usern, p)
s.sendmail(usern, toaddr, msg.as_string())
s.quit()
谢谢!
输入空行退出
print("Body? ", end="")
lines = []
while True:
line = input("")
if not len(line):
break
lines.append(line)
print("\n".join(lines))
我无法添加评论以查看这是否完全符合您的要求,但我会提前给出。
您的 msginp = input('Body? ')
在您按下回车键后结束,您需要输入 \n
才能换行。而不是每次都输入 \n
就可以循环。
收集完所有数据后,您就可以像以前一样使用 MIMEText。
用这个替换你的 msginp 和 MIMEText(总计是 msginp)
total = ""
temp = input("Data: ")
total = temp+"\n"
while(temp!=""):
temp = input("next line: ")
total = total+temp+"\n"
msg = MIMEText(total)
我正在尝试制作一个发送电子邮件的脚本。但是怎么换行呢?我尝试了以下方法:
将msg = MIMEText(msginp)
更改为msg=MIMEText(msginp,_subtype='plain',_charset='windows-1255')
NOTE: msginp is a input (
msginp = input('Body? ')
)
有人知道如何换行吗?喜欢键盘上的 enter
键吗?
我的代码是:
import smtplib
from email.mime.text import MIMEText
import getpass
smtpserverinp = input('What SMTP server are you using? (Look here for more information. https://sites.google.com/view/smtpserver) ')
usern = input('What is your email adderess? ')
p = getpass.getpass(prompt='What is your password? (You will not see that you are typing because it is a password) ')
subjectss = input('Subject? ')
msginp = input('Body? ')
toaddr = input('To who do you want to send it to? ')
msg = MIMEText(msginp)
msg['Subject'] = subjectss
msg['From'] = usern
msg['To'] = toaddr
s = smtplib.SMTP(smtpserverinp, 587)
s.starttls()
s.login(usern, p)
s.sendmail(usern, toaddr, msg.as_string())
s.quit()
谢谢!
输入空行退出
print("Body? ", end="")
lines = []
while True:
line = input("")
if not len(line):
break
lines.append(line)
print("\n".join(lines))
我无法添加评论以查看这是否完全符合您的要求,但我会提前给出。
您的 msginp = input('Body? ')
在您按下回车键后结束,您需要输入 \n
才能换行。而不是每次都输入 \n
就可以循环。
收集完所有数据后,您就可以像以前一样使用 MIMEText。
用这个替换你的 msginp 和 MIMEText(总计是 msginp)
total = ""
temp = input("Data: ")
total = temp+"\n"
while(temp!=""):
temp = input("next line: ")
total = total+temp+"\n"
msg = MIMEText(total)