아 리 클 라 우 드 메 일 발송 25 포트 사용 불가 문제 해결
우선,아 리 가 크게 준 공식 적 인 해결 방안 입 니 다.SMTP 로 메 일 을 보 냅 니 다.코드 는 다음 과 같 습 니 다.
# -*- coding:utf-8 -*-
import urllib, urllib2
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
#      ,             
username = '[email protected]'
#      ,             
password = 'XXXXXXXX'
#        ,       ,  30 
rcptlist = ['[email protected]', '[email protected]']
receivers = ','.join(rcptlist)
#    multipart      
msg = MIMEMultipart('mixed')
msg['Subject'] = 'Test Email'
msg['From'] = username
msg['To'] = receivers
#    multipart/alternative   text/plain   
alternative = MIMEMultipart('alternative')
textplain = MIMEText('     ', _subtype='plain', _charset='UTF-8')
alternative.attach(textplain)
#    multipart/alternative   text/html   
texthtml = MIMEText('     ', _subtype='html', _charset='UTF-8')
alternative.attach(texthtml)
#   alternative    mixed    
msg.attach(alternative)
#     
# xlsx      
xlsxpart = MIMEApplication(open('    1.xlsx', 'rb').read())
xlsxpart.add_header('Content-Disposition', 'attachment', filename=Header("    1.xlsx","utf-8").encode())
msg.attach(xlsxpart)
# jpg      
jpgpart = MIMEApplication(open('2.jpg', 'rb').read())
jpgpart.add_header('Content-Disposition', 'attachment', filename=Header("2.jpg","utf-8").encode())
msg.attach(jpgpart)
# mp3      
mp3part = MIMEApplication(open('3.mp3', 'rb').read())
mp3part.add_header('Content-Disposition', 'attachment', filename=Header("3.mp3","utf-8").encode())
msg.attach(mp3part)
#     
try:
  client = smtplib.SMTP()
  #python 2.7    ,     SSL,      client
  #client = smtplib.SMTP_SSL()
  client.connect('smtpdm.aliyun.com')
  client.login(username, password)
  #            
  client.sendmail(username, rcptlist, msg.as_string())
  client.quit()
  print '      !'
except smtplib.SMTPRecipientsRefused:
  print '      ,      '
except smtplib.SMTPAuthenticationError:
  print '      ,    '
except smtplib.SMTPSenderRefused:
  print '      ,      '
except smtplib.SMTPException,e:
  print '      , ', e.message
다음은 두 네티즌 이 제공 한 간단 한 해결 방안 이다.
이게 간소 화 된 SMTP 방식 이에 요.
import smtplib
from email.mime.text import MIMEText
msg_from = '[email protected]' #      
passwd = '****' #            (        ,       )
msg_to = ['****@qq.com','**@163.com','*****@163.com'] #      
subject = "    " #   
content = "    ,      ,   "
#     MIMEText  (        )
# _text_:    
msg = MIMEText(content)
#       
msg['Subject'] = subject
#        
# msg['Subject'] = Header(subject, 'utf-8')
#      
msg['From'] = msg_from
#      
msg['To'] = '[email protected]'
# msg['To'] = '       '
try:
  #   ssl    ,     ,  
  s = smtplib.SMTP_SSL("smtp.qq.com", 465)
  #      
  s.login(msg_from, passwd)
  #     :   ,   ,      
  s.sendmail(msg_from, msg_to, msg.as_string())
  print('  ')
except s.SMTPException as e:
  print(e)
finally:
  s.quit()setting.py 설정 은 다음 과 같 습 니 다.
# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.qq.com' #     163    smtp.163.com
EMAIL_PORT = 465  #    
EMAIL_HOST_USER = '[email protected]' #         
EMAIL_HOST_PASSWORD = '***' #          
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
#       ,          
#DEFAULT_FROM_EMAIL = 'lqz<'[email protected]>'
EMAIL_USE_SSL = True  #  ssl
#EMAIL_USE_TLS = False #   tls
#EMAIL_USE_SSL   EMAIL_USE_TLS     ,        True
from django.core.mail import send_mail  #       
from threading import Thread   #       
from threading import Thread
  t1 = Thread(target=send_mail,args=(
  '  %s   %s   '%(article_name,user_name),
  '      :%s'%(content),
  settings.EMAIL_HOST_USER,
  ['[email protected]'] )) 
  t1.start()이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Centos 7 설정 Nginx - Aliyun ECSCentos 7 설정 Nginx, 자주 사용 하 는 nginx 작업, 시작 / 정지, 프 록 시, 역방향 프 록 시 설정 및 https ssl 443 설정 nginx 기 존 모듈 보기 configure argumen...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.