SMTPLIB Python 3中的换行符
我正在尝试制作一个发送电子邮件的脚本。但是怎么做换行呢?我尝试了以下方法: 将SMTPLIB Python 3中的换行符,python,python-3.x,email,smtplib,Python,Python 3.x,Email,Smtplib,我正在尝试制作一个发送电子邮件的脚本。但是怎么做换行呢?我尝试了以下方法: 将msg=MIMEText(msginp)更改为msg=MIMEText(msginp,_subtype='plain',_charset='windows-1255') 注意:msginp是一个输入(msginp=input('Body'))) 有人知道怎么换行吗?像键盘上的enter键 我的代码是: import smtplib from email.mime.text import MIMEText import
msg=MIMEText(msginp)
更改为msg=MIMEText(msginp,_subtype='plain',_charset='windows-1255')
注意:msginp是一个输入(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')
在按下enter键后结束,您需要输入新行\n
。而不是每次都键入\n
,您可以进行循环。
收集完所有数据后,可以像以前一样使用MIMEText
用此替换msginp和MIMEText(总计为msginp)
我认为在航站楼没有简单/直接的方法可以做到这一点。是时候开始研究一个简单的GUI库了,比如
total = ""
temp = input("Data: ")
total = temp+"\n"
while(temp!=""):
temp = input("next line: ")
total = total+temp+"\n"
msg = MIMEText(total)