我正在尝试使用python smtplib模块发送邮件,但是我收到了错误。
import smtplib
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.login("xxxxxxxx@gmail.com", "yyyyyyy")
message = "Message_you_need_to_send"
s.sendmail("xxxxxxxxx@gmail.com", "aaaaaaaaa@gmail.com", message)
s.quit()
我收到如下错误:
追踪(最近一次调用最后一次):文件" /home/engineer/demo.py", 第52行 s.starttls()File" /usr/lib/python2.7/smtplib.py" ;,第637行,在starttls中 提出SMTPException("服务器不支持STARTTLS扩展名。")SMTPException:服务器不支持STARTTLS扩展名。
答案 0 :(得分:0)
我从另一个链接中引用解决方案。您可以尝试在s.starttls()
之前删除s.set_debuglevel(1)
。
我使用自己的gmail帐户测试了您的代码,似乎代码应该与s.echlo()一起使用。您可以查看您的Gmail安全设置,例如启用安全性较低的应用,Let less secure apps use your account
您还可以使用import smtplib
s = smtplib.SMTP('smtp.gmail.com', 587)
s.set_debuglevel(1)
s.ehlo()
s.starttls()
REPORT Z_JOIN_employees.
TABLES: pa0021, pa0002,dd07v.
type-pools:slis.
TYPES: BEGIN OF ty_pa0021 ,
pernr TYPE pa0021-pernr,
favor TYPE pa0021-favor,
fanam TYPE pa0021-fanam,
fasex TYPE pa0021-fasex,
Gender TYPE Char20,
SUBTY TYPE pa0021-SUBTY,
END OF ty_pa0021.
TYPES: BEGIN OF ty_pa0002,
pernr TYPE pa0002-pernr,
perid TYPE pa0002-perid,
VORNA TYPE pa0002-VORNA,
NACHN TYPE pa0002-NACHN,
gesch TYPE pa0002-gesch,
GBDAT TYPE pa0002-GBDAT,
AGE(2),
YEAR(2),
END OF ty_pa0002.
TYPES: BEGIN OF ty_final,
pernr TYPE pa0021-pernr,
perid TYPE pa0002-perid,
VORNA TYPE pa0002-VORNA,
NACHN TYPE pa0002-NACHN,
gesch TYPE pa0002-gesch,
GBDAT TYPE pa0002-GBDAT,
favor TYPE pa0021-favor,
fanam TYPE pa0021-fanam,
SUBTY TYPE pa0021-SUBTY,
fasex TYPE pa0021-fasex,
Gender TYPE Char20,
AGE(2),
YEAR(2),
End OF ty_final.
DATA: wa_pa0021 TYPE ty_pa0021,
it_pa0021 TYPE TABLE OF ty_pa0021 WITH HEADER LINE,
it_temp_21 like PA0021 OCCURS 0 WITH HEADER LINE,
wa_temp_21 like LINE OF it_temp_21,
wa_pa0002 TYPE ty_pa0002,
it_pa0002 TYPE TABLE OF ty_pa0002,
wa_final TYPE ty_final,
it_final TYPE TABLE OF ty_final.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA : BIRTHDATE LIKE pa0002-gbdat,
DAYS TYPE NUM2,
MONTHS TYPE NUM2,
YEARS TYPE NUM2.
CONSTANTS : iv_domname TYPE dd07l-domname VALUE 'GESCH'.
DATA : gt_dd07v TYPE TABLE OF dd07v WITH KEY domname WITH HEADER LINE .
START-OF-SELECTION.
SELECT-OPTIONS: s_pernr FOR pa0021-pernr.
SELECT *
FROM pa0021
INTO CORRESPONDING FIELDS OF TABLE it_temp_21
WHERE pernr IN s_pernr.
CALL FUNCTION 'GET_DOMAIN_VALUES'
EXPORTING
DOMNAME = iv_domname
TEXT = 'X'
FILL_DD07L_TAB = ' '
TABLES
VALUES_TAB = gt_dd07v
EXCEPTIONS
NO_VALUES_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
*** Implement suitable error handling here
ENDIF.
LOOP at it_temp_21 into wa_temp_21.
it_pa0021-pernr = wa_temp_21-pernr.
it_pa0021-favor = wa_temp_21-favor.
it_pa0021-fanam = wa_temp_21-fanam.
it_pa0021-fasex = wa_temp_21-fasex.
it_pa0021-SUBTY = wa_temp_21-SUBTY.
APPEND it_pa0021 to it_pa0021.
ENDLOOP.
LOOP AT it_pa0021 INTO wa_pa0021.
READ TABLE it_pa0002 INTO wa_pa0002 WITH KEY pernr = wa_pa0021-pernr.
if sy-subrc eq 0.
WA_FINAL-pernr = WA_pa0021-pernr.
WA_FINAL-perid = WA_pa0002-perid.
WA_FINAL-VORNA = WA_pa0002-VORNA.
WA_FINAL-NACHN = WA_pa0002-NACHN.
WA_FINAL-gesch = WA_pa0002-gesch.
WA_FINAL-GBDAT = WA_pa0002-GBDAT.
WA_FINAL-favor = WA_pa0021-favor.
WA_FINAL-fanam = WA_pa0021-fanam.
WA_FINAL-SUBTY = WA_pa0021-SUBTY.
WA_FINAL-fasex = WA_pa0021-fasex.
READ TABLE gt_dd07v WITH KEY domvalue_l = WA_pa0021-fasex.
MOVE gt_dd07v-ddtext TO WA_FINAL-gender.
BIRTHDATE = WA_pa0002-GBDAT.
CALL FUNCTION 'HRCM_TIME_PERIOD_CALCULATE'
EXPORTING
BEGDA = BIRTHDATE
ENDDA = SY-DATUM
IMPORTING
NOYRS = YEARS
NOMNS = MONTHS
NODYS = DAYS
EXCEPTIONS
INVALID_DATES = 1
OVERFLOW = 2.
* OTHERS = 3.
wa_final-age = years.
APPEND WA_FINAL TO IT_FINAL.
CLEAR WA_FINAL.
*
* WRITE : YEARS , 'years' , MONTHS , 'months' , DAYS , 'days'.
endif.
*build field catalog for alv table.
PERFORM build_catalog.
"BUILD FIELDCATALOG
WA_FIELDCAT-FIELDNAME = 'pernr'.
WA_FIELDCAT-SELTEXT_M = 'Personnel Number'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'perid'.
WA_FIELDCAT-SELTEXT_M = 'IC No'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'vorna'.
WA_FIELDCAT-SELTEXT_M = 'First Name'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'nachn'.
WA_FIELDCAT-SELTEXT_M = 'Last Name'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'gesch'.
WA_FIELDCAT-SELTEXT_M = 'Gender'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'GBDAT'.
WA_FIELDCAT-SELTEXT_M = 'Birthday'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'AGE(2)'.
WA_FIELDCAT-SELTEXT_M = 'AGE'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'FAVOR'.
WA_FIELDCAT-SELTEXT_M = 'First Name of Family member'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'FANAM'.
WA_FIELDCAT-SELTEXT_M = 'Last Name of Family member'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'SUBTY'.
WA_FIELDCAT-SELTEXT_M = 'Relationship'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'FASEX'.
WA_FIELDCAT-SELTEXT_M = 'Gender of family member'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'GENDER'.
WA_FIELDCAT-SELTEXT_M = 'Gender description'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = IT_FIELDCAT
TABLES
T_OUTTAB = IT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDLOOP.
*& Form BUILD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
ENDFORM.
答案 1 :(得分:0)
就代码而言,没有任何变化,最终发现,问题与足够的防火墙权限相关联。