666.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from boto3.session import Session
  2. import traceback
  3. AWS_ACCESS_ID = 'AKIAJKPU23EU5QWHFPKQ'
  4. AWS_ACCESS_SECRET = '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'
  5. AWS_ACCESS_REGION = 'us-east-1'
  6. COMPANY_EMAIL = 'user_server@nsst.com'
  7. class SesClassObject:
  8. def __init__(self, *args, **kwargs):
  9. self.access_id = AWS_ACCESS_ID
  10. self.access_secret = AWS_ACCESS_SECRET
  11. self.region_name = AWS_ACCESS_REGION
  12. self.company_email = COMPANY_EMAIL
  13. session = Session(
  14. aws_access_key_id=AWS_ACCESS_ID,
  15. aws_secret_access_key=AWS_ACCESS_SECRET,
  16. region_name=AWS_ACCESS_REGION,
  17. )
  18. self.conn = session.client('ses')
  19. def send_email(self, send_address_list=[], subject='', body=''):
  20. try:
  21. response = self.conn.send_email(
  22. # 发送人
  23. Source=self.company_email,
  24. Destination={
  25. # 收件人
  26. 'ToAddresses': send_address_list
  27. },
  28. Message={
  29. # 标题
  30. 'Subject': {
  31. 'Data': subject,
  32. 'Charset': 'utf-8'
  33. },
  34. 'Body': {
  35. 'Html': {
  36. 'Data': body,
  37. 'Charset': 'utf-8'
  38. }
  39. }
  40. },
  41. )
  42. except Exception as e:
  43. errorInfo = traceback.format_exc()
  44. print(errorInfo)
  45. self.send_email(send_address_list=[self.company_email], subject='邮件发送错误信息提醒',
  46. body='<br>请向开发人员反馈并修改</br>' + '\n错误信息位' + str(errorInfo))
  47. if response['MessageId']:
  48. return True
  49. else:
  50. print(response)
  51. self.send_email(send_address_list=[self.company_email], subject='邮件发送错误信息提醒', body='<br>请向开发人员反馈并修改</br>')
  52. return False
  53. ses = SesClassObject()
  54. send_res = ses.send_email(
  55. send_address_list=['1758730877@qq.com'],
  56. subject='P2P日志文件',
  57. body='test')
  58. from var_dump import var_dump
  59. var_dump(send_res)