如果你想用 Python 编写一个程序来祝福母亲节快乐,你可以简单地打印一条消息
到控制台。但如果你想让它更有趣或更个性化,你可以添加一些额外的功能,比如
发送电子邮件、制作一个简单的图形界面等。
以下是一个简单的 Python 脚本,用于在控制台上输出“母亲节快乐”的消息:
python
def
wish_mothers_day
():
print
("母亲节快乐!")
wish_mothers_day()
如果你想发送一封电子邮件来祝福母亲节快乐,你可以使用 smtplib 和 email.mime
模块(但请注意,为了发送电子邮件,你需要一个 SMTP 服务器和相应的凭据):
python
import
smtplib
from
email.mime.text import MIMEText
from
email.mime.multipart import MIMEMultipart
def
send_mothers_day_email(to_email, smtp_server, smtp_port, user,
password
):
msg = MIMEMultipart()
msg[
'From'] = user
msg[
'To'] = to_email
msg[
'Subject'] = '母亲节快乐!'
body =
'亲爱的妈妈,祝您母亲节快乐!'
msg.attach(MIMEText(body,
'plain'))
with
smtplib.SMTP(smtp_server, smtp_port) as server:
server.login(user, password)
server.sendmail(user, to_email, msg.as_string())
print
(f"已向 {to_email} 发送母亲节祝福邮件!")
#
使用你的电子邮件凭据和收件人地址替换以下参数
send_mothers_day_email(
'recipient@example.com', 'smtp.example.com',
587
, 'your-email@example.com', 'your-password')
请注意,上面的电子邮件发送代码只是一个示例,并且为了安全起见,你不应该在
代码中硬编码密码或其他敏感信息。相反,你应该使用环境变量、配置文件或其他
安全方法来存储这些信息。