-1

python语音到电子邮件不起作用。一切正常。它记录并给我我的消息输出,但它不发送密码。

import speech_recognition as sr
import yagmail

recognizer=sr.Recognizer()

with sr.Microphone() as source:
 print('clearing background noises:')

 recognizer.adjust_for_ambient_noise(source,duration=1)
 print("waiting for your message...")

 recordedaudio = recognizer.listen(source)
 print('done recording...!')

 try:
  print('printing the message..')
  text=recognizer.recognize_google(recordedaudio,language='en,US')

  print('Your message:{}'.format(text))

 except Exception as ex:
  print(ex)

  #automate mails:

  reciever='dipinak@gmail.com'
  message=text

  sender=yagmail.SMTP('manas.rdp@gmail.com')
  sender.send(to=reciever,subject='this is an automated email written by manas using python',contents=message)
4

1 回答 1

0

收到您的 txt 消息后,您可以像这样发送它,如果您想添加语音消息本身,您也可以附加它。注意:如果安全性不符合他们的标准,谷歌可能会尝试阻止该应用程序。

import yagmail

# beforehand, you take your message text here...

try:
    password = 'yourpasshere'
    sender = 'youremail@gmail.com'
    recv = 'reciever@gmail.com'
    msg = 'Your message:{}'.format(text)
    #in case you want to attach a voice message
    attach = '/path_to_your_voice_mesage/test.mp3'

    #initializing the server connection
    yag = yagmail.SMTP(user=sender, password=password)
    #sending the email

    yag.send(to=recv, subject='voice', smtp_ssl=False,
                contents=msg, attachments=attach)
except:
    print("Error, email was not sent")
else:
    print('Email sent successfully :)')

于 2021-12-12T09:05:50.327 回答