我有从用户输入发送电子邮件的问题[python3.6]

时间:2018-05-04 21:14:21

标签: python-3.x

我正在尝试添加一个用户输入其姓名,电子邮件和问题的系统。我一直收到以下错误:

这是我运行脚本时遇到的错误。

python techsupport.py
Exception in Tkinter callback
Traceback (most recient call last):
   File C:\__init__.py, line 1699 in __call__ return self.func(*args)
   File C:\smtplib.py, line 867, in sendmail raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (501, b'5.5.4 Invalid arguments', test@mail.com')

注意:smtp服务器和端口是正确的。出于安全考虑,我只是没有把它们放在这里。

以下是当前代码:

from tkinter import *
from tkinter import ttk
import smtplib
import os
import mimetypes
from tkinter import messagebox
import tkinter.messagebox as tm
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders

def submit_command():
    if (user_fname.get() and user_lname.get() and user_email.get()):
        email_user = user_email.get()
        email_send = 'myemail@domain.com'
        subject = "Tech Support"
        msg = MIMEMultipart()
        msg['From'] = email_user
        msg['To'] = email_send
        msg['Subject'] = subject
        body = t1.get('1.0', END)
        text = msg.as_string()
        server = smtplib.SMTP('ServerIP', Port)
        server.starttls()
        server.sendmail(email_user, email_send, text, body)
        server.quit()
        print(email_user + '\n' + email_send + '\n' + text + '\n' + body)
        messagebox.showinfo("Thank You...","Your request has been sent. We will get back to you as soon as we can!")
        tech.destroy()
    else:
        messagebox.showinfo("Missing Fields", "You must fill in all fields...")

tech = Tk()
tech.configure(background='grey15')
tech.title("Technical Support Ticket")
tech.iconbitmap('img.ico')
width = 350
height = 450
screen_width = tech.winfo_screenwidth()
screen_height = tech.winfo_screenheight()
x = (screen_width/2) - (width/2)
y = (screen_height/2) - (height/2)
tech.geometry("%dx%d+%d+%d" % (width, height, x, y))
tech.resizable(0, 0)

l1 = Label(tech, text="First Name...")
l1.pack(padx=2, pady=2)

user_fname=StringVar()
e1 = ttk.Entry(tech, textvariable=user_fname)
e1.pack(padx=2, pady=2)

l2 = Label(tech, text="Last Name...")
l2.pack(padx=2, pady=2)

user_lname=StringVar()
e2 = ttk.Entry(tech, textvariable=user_lname)
e2.pack(padx=2, pady=2)

l3 = Label(tech, text="Email Address...")
l3.pack(padx=2, pady=2)

user_email=StringVar()
e3 = ttk.Entry(tech, textvariable=user_email)
e3.pack(padx=2, pady=2)

l4 = Label(tech, text="Explain in detail what the issue is.")
l4.pack(padx=2, pady=2)

t1 = Text(tech, wrap=WORD, height=1)
t1.pack(fill=BOTH, expand=1, padx=2, pady=2)

b1 = Button(tech, text="Submit", width=12, command=submit_command)
b1.pack(padx=5, pady=5)

tech.mainloop()

有什么东西我做错了,或者我缺少的东西?

谢谢!

1 个答案:

答案 0 :(得分:1)

从SMTP服务器返回的501代码表示您发送的电子邮件不合适。我假设你遇到了这个错误,然后连接就可以了,但是服务器拒绝了你的电子邮件。

如果电子邮件被识别为垃圾邮件或服务器无法将其转换为fully qualified email address.

,则可能会发生这种情况

您的错误中的电子邮件看起来像是可以被拒绝的电子邮件,因此可能会更改您的电子邮件。

相关问题