12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- from boto3.session import Session
- import traceback
- AWS_ACCESS_ID = 'AKIAJKPU23EU5QWHFPKQ'
- AWS_ACCESS_SECRET = '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'
- AWS_ACCESS_REGION = 'us-east-1'
- COMPANY_EMAIL = 'user_server@nsst.com'
- class SesClassObject:
- def __init__(self, *args, **kwargs):
- self.access_id = AWS_ACCESS_ID
- self.access_secret = AWS_ACCESS_SECRET
- self.region_name = AWS_ACCESS_REGION
- self.company_email = COMPANY_EMAIL
- session = Session(
- aws_access_key_id=AWS_ACCESS_ID,
- aws_secret_access_key=AWS_ACCESS_SECRET,
- region_name=AWS_ACCESS_REGION,
- )
- self.conn = session.client('ses')
- def send_email(self, send_address_list=[], subject='', body=''):
- try:
- response = self.conn.send_email(
- # 发送人
- Source=self.company_email,
- Destination={
- # 收件人
- 'ToAddresses': send_address_list
- },
- Message={
- # 标题
- 'Subject': {
- 'Data': subject,
- 'Charset': 'utf-8'
- },
- 'Body': {
- 'Html': {
- 'Data': body,
- 'Charset': 'utf-8'
- }
- }
- },
- )
- except Exception as e:
- errorInfo = traceback.format_exc()
- print(errorInfo)
- self.send_email(send_address_list=[self.company_email], subject='邮件发送错误信息提醒',
- body='<br>请向开发人员反馈并修改</br>' + '\n错误信息位' + str(errorInfo))
- if response['MessageId']:
- return True
- else:
- print(response)
- self.send_email(send_address_list=[self.company_email], subject='邮件发送错误信息提醒', body='<br>请向开发人员反馈并修改</br>')
- return False
- ses = SesClassObject()
- send_res = ses.send_email(
- send_address_list=['1758730877@qq.com'],
- subject='P2P日志文件',
- body='test')
- from var_dump import var_dump
- var_dump(send_res)
|