Send email using my yahoo account - error message

不羁岁月 提交于 2020-07-06 04:09:09

问题


I use Python 3.5.2.

I am trying to use my yahoo account to send email. I use the yahoo SMTP server domain name smtp.mail.yahoo.com according to this website `http://neerajbyte.com/send-email-through-python-console-with-gmail-hotmail-and-yahoo/'. However I got an error message (below). Normally for security reasons google, I tried it, would send me an email notifying me of an application trying to access my account and I have to click on a link to allow it. But I didn't get an email from yahoo but just this error message, not sure why.

this is my code:

>>> import smtplib
>>> conn = smtplib.SMTP('smtp.mail.yahoo.com', 587)
>>> type(conn)
<class 'smtplib.SMTP'>
>>> conn
<smtplib.SMTP object at 0x02AD9A70>
>>> conn.ehlo()
(250, b'smtp.mail.yahoo.com\nPIPELINING\nSIZE 41697280\n8 BITMIME\nSTARTTLS')
>>> conn.starttls
<bound method SMTP.starttls of <smtplib.SMTP object at 0x02AD9A70>>
>>> conn.login('j@yahoo.com', 'j2')

this is my error message:

_Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    conn.login('j@yahoo.com', 'j2')
  File "C:\Users\J\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 696, in login
    "SMTP AUTH extension not supported by server.")
smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.
_

回答1:


To my knowledge, Yahoo and Gmail expect 2-factor authentication when trying to login from apps. These are the steps:

  1. In Yahoo, you can go to Account Info.

  2. Click on the Account Security tab on the left. Enable 2-step verification. I then first time you try this you will get options to select the method of verification. Usually I choose OTP via SMS.

  3. Then you can Manage App Passwords. This will bring up a popup to generate a 16-character password. This is what you can use from your app when logging into your mail.

Below is a sample screenshot:




回答2:


follow the Article https://support.google.com/accounts/answer/185833?hl=en

Create & use App Passwords for gmail notification using ansible mail module.

generate Apps password, and use same 16 digit app password in your anisble playbook

     - name: 'ansible mail module to gmail notification'
      mail:
        host: smtp.gmail.com
        subtype: html
        port: 587
        password: **************
        to: XXXXXXXXXX@gmail.com
        from: YYYYYYYYYY.YYYY@gmail.com
        username: YYYYYYYYYY.YYYY@gmail.com
        subject: User details report
        attach: /tmp/data_details/data_details.csv
        body:  {{ lookup('file', '/tmp/data_details/data_details.csv') }} 
      delegate_to: localhost

now try to send email it should work. i have tested successfully and it's working.




回答3:


another best way to use ansible vault password string variable while writing playbook for mail module. do not compromise security risk.

i have implemented same for sending email using mail module and it's working as expected.

ansible-vault encrypt_string yourgmailapppassword --name gmail_password

use above method to encrypt gmail app password using ansible vault string option and define encrypted variable into the playbook.

cat fetch-users-deatils.yml

    - name: Linux servers user audit report preparation
      hosts: "{{ HOSTS }}"
      roles:
        - user-collections
    
    - name: Refreshing user Dashboard & sending email from localhost
      hosts: localhost
      become: false
      vars:
       - gmail_password: !vault |
              $ANSIBLE_VAULT;1.1;AES256
              62613232383962323430633831113465356231563163366235353034393230656331663436646233
              3266353862303738303737383530313664356135336661390a336562613436626665333833323030
              61393135643433313930643337363465343332353716333831222766376137396430426361663633
              6233313433633231320a663435636230636431643731333166366435346564316331323361633566
              38622138392437888466666535323432653034323936353961646233613437343831
      tasks:
        - name: Collecting the user details information and recreating the users dashboard
          script: dashboard_user.sh
          tags: user_dashboard
    
    
        - name: User Audit data output file stored on below location
          debug:
            msg:
             /tmp/user_collection/user_details.csv
    
        - name: 'Sending Ansible users report email'
          mail:
            host: smtp.gmail.com
            subtype: html
            port: 587
            password: "{{ gmail_password }}"
            to: abcdefghijkl@gmail.com
            from: abcdefghijkl@gmail.com
            username: abcdefghijkl@gmail.com
            subject: User details report
            attach: /tmp/user_collection/user_details.csv
            body: <pre> {{ lookup('file', '/tmp/user_collection/user_details.csv') }} </pre>
          delegate_to: localhost

below is ansible playbook execution command

ansible-playbook fetch-users-deatils.yml -e "HOSTS=all" --ask-vault-pass


来源:https://stackoverflow.com/questions/40904957/send-email-using-my-yahoo-account-error-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!