提问人:Andrey 提问时间:9/21/2023 更新时间:9/21/2023 访问量:61
我想向一个电子邮件地址发送电子邮件,该电子邮件地址将通过 Telegram 机器人向用户发送
I want to send an email to an email address that will send users via Telegram bot
问:
我想实现这个逻辑。用户在机器人中输入其电子邮件、电子邮件主题和电子邮件说明。然后,机器人处理这封信并将其发送到 [email protected]。问题出现了,要发送一封信,您需要smtp_password,这与常规邮件密码不同,也许有办法在不要求用户太多的情况下获取此密码?
也许在Python或Java上有一个现成的解决方案?
Tried different code like this
import smtplib
from email.mime.text import MIMEText
def send_email(sender_email, recipient_email, subject, message):
smtp_server = 'smtp.google.com'
smtp_port = 587
smtp_username = User_name
smtp_password = User_password
msg = MIMEText(message)
msg['Subject'] = subject
msg['From'] = sender_email
msg['To'] = recipient_email
try:
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(smtp_username, smtp_password)
server.send_message(msg)
print('Email sent successfully.')
except Exception as e:
print(f'Failed to send email. Error: {str(e)}')
sender_email = input('Enter your sender email: ')
recipient_email = input('Enter recipients address: ')
subject = input('Enter the subject of the message: ')
message = input('Enter message text: ')
send_email(sender_email, recipient_email, subject, message)
答: 暂无答案
评论