Здравствуйте! Вот код:
import telebot
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import ssl
sender_email = "tsendmail095@gmail.com"
password = "12345678AbC"
context = ssl.create_default_context()
msg = MIMEMultipart("alternative")
bot = telebot.TeleBot("1011976361:AAFJIZsT0ECNTHa_Kx6zB_tfDh8KzbwGZyA")
keyboard = telebot.types.ReplyKeyboardMarkup(True, True)
keyboard.row("Отправить письмо")
domen = "foo-example.com"
global link
link = ""
global receiver_email
receiver_email = ""
msg["Subject"] = "test"
msg["From"] = sender_email
msg["To"] = receiver_email
if link == "" and receiver_email == "":
@bot.message_handler(commands=['start'])
def hello(message):
bot.send_message(message.chat.id, "", reply_markup=keyboard)
@bot.message_handler(content_types=['text'])
def request_email(message):
if message.text.lower() == "отправить письмо":
bot_message = bot.send_message(message.chat.id, "Введите почту получателя!")
bot.register_next_step_handler(bot_message, check_email)
def check_email(message):
if "@" in message.text:
receiver_email = message.text
print(receiver_email)
bot_message = bot.send_message(message.chat.id, "")
bot.register_next_step_handler(bot_message, check_link)
else:
bot_message = bot.send_message(message.chat.id, 'В почте должен присутствовать знак "@"!')
bot.register_next_step_handler(bot_message, check_email)
print(receiver_email)
def check_link(message):
link = message.text
if domen in link:
bot_message = bot.send_message(message.chat.id, "Отправляю письмо!")
print(link)
part = MIMEText(html, "html")
msg.attach(part)
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_email, password)
server.sendmail(
sender_email, receiver_email, msg.as_string()
)
else:
bot_message = bot.send_message(message.chat.id, "Домен недействителен!")
bot.register_next_step_handler(bot_message, check_link)
link = ""
print(link)
Выдаёт ошибку: smtplib.SMTPRecipientsRefused {'' (555, b'5.5.2 Syntax Error. b1sm1699862ljp.72 - gsmtp)}
Я понимаю, что ошибка в синтаксисе, но никак не пойму где. Заранее спасибо!