在Ubuntu服务器中创建一个定时任务,每天执行脚本获取账单信息,并通过Python发送邮件到相关人员。
1、在Ubuntu中获取的账单信息后进行了对齐格式的操作,类似如下:
2021-07-23
美区账单总和: $40212.09
中国区账单总和: ¥14296.45
1.各账号花费总和
matser@gmail.com: $23804.34
matser-1@huafeng.com: $7680.83
matser-2@huafeng.com: $1306.30
2.各账号花费详情
master@gmail.com
EC2 $0.93
MySQL $85.17
Redis $0.12
DynamoDB $925.17
master-2@huafeng.com
EC2 ¥5.04
MySQL ¥385.89
Redis ¥320.65
DynamoDB ¥22.45
2、获取账单后使用Python发送邮件到相关人员,Python代码如下:
```python
import smtplib
import time
from email.mime.text import MIMEText
from email.utils import formataddr
#SMTP服务器地址和端口
smtp_server = 'smtp.outlook.com'
tls_port = '587'
#发件人邮箱地址和密码
sender = '123456@huafeng.com'
password = '123456789'
#收件人邮箱地址
recipient = '456789@huafeng.com'
#当前月份
month = time.strftime("%m",time.localtime())
#账单
f = open("/root/scripts/bill.txt",'r','utf-8')
bill_cost = ''' '''
while True:
line = f.readline()
bill_cost += line.strip()+'\n'
if not line:
break
f.close()
#初始化邮件
msg = MIMEText(bill_cost,'plain','utf-8')
msg['From'] = formataddr(["lrving",sender])
msg['To'] = formataddr(["jack",recipient])
msg['Subject'] = f"2021年{month}月账号账单"
#SMTP发送邮件
server = smtplib.SMTP(smtp_server, tls_port)
server.set_debuglevel(True)
server.ehlo()
server.starttls()
server.ehlo()
server.login(sender, password)
server.sendmail(sender,recipient,msg.as_string())
server.quit()
问题一:
发送到outlook中的邮件并没有对齐格式,格式杂乱无章的排列,歪歪扭扭的,看这个很别扭,如图所示:
这个要如何在Python中设置才能将发出的邮件和原来的格式一样对齐呢?
问题二:
发送到outlook的字体大小太小了,看着贼费劲,如何调整发送到outlook的字体大小?
请问这两个要如何解决呀?