def gmail_send(sender, receiver, password): """ Interact with gmail api to send mails """ yag = yagmail.SMTP(user=sender, password=password) speech_ui.playsound("./data/ask-subject.mp3") subject = speech_ui.take_voice() if (subject == "null" or subject == "empty"): subject = "" speech_ui.playsound("./data/ask-contents.mp3") body = speech_ui.take_voice() while True: if (speech_ui.confirm(body)): break else: continue speech_ui.playsound("./data/ask-attachment.mp3") if (speech_ui.YesOrNo()): speech_ui.playsound("./data/ask-file.mp3") filename = speech_ui.take_voice() filename = file_handler.search_file(filename) if (filename == ""): speech_ui.playsound('./data/send-blank.mp3') if (speech_ui.YesOrNo()): yag.send(to=receiver, subject=subject, contents=body) else: cleanexit.quit() else: yag.send(to=receiver, subject=subject, contents=body, attachments=filename) speech_ui.playsound("./data/email_sent.mp3")
def get_dest_email(): """Ask for email """ speech_ui.playsound('./data/ask-destmail.mp3') text = speech_ui.take_voice() e_mail = text.replace('at', '@').replace(' ', '').replace('dot', '.') while True: if (speech_ui.confirm(e_mail)): break else: continue return e_mail
def get_password(): """Ask for password """ speech_ui.playsound('./data/ask-password.mp3') text = speech_ui.take_voice() password = text.replace(' ', '') while True: if (speech_ui.confirm(password)): break else: continue return password
def get_name(): """Ask for username """ speech_ui.playsound('./data/ask-name.mp3') text = speech_ui.take_voice() name = text.replace(' ', '') while True: if (speech_ui.confirm(name)): break else: continue return name
def compose_mail(sender, reciever): """ This method composes the email with acceptable standards and retunrns as a message string """ sender_email = sender receiver_email = reciever speech_ui.playsound("./data/ask-subject.mp3") subject = speech_ui.take_voice() if (subject == "null" or subject == "empty"): subject = "" speech_ui.playsound("./data/ask-contents.mp3") body = speech_ui.take_voice() while True: if (speech_ui.confirm(body)): break else: continue #Ask if attachment is needed speech_ui.playsound("./data/ask-attachment.mp3") if (speech_ui.YesOrNo()): #Ask name of attchments speech_ui.playsound('./data/ask-file.mp3') filename = speech_ui.take_voice() filename = file_handler.search_file(filename) if (filename == ""): speech_ui.playsound('./data/send-blank.mp3') if (speech_ui.YesOrNo()): msg = MIMEText(body) msg['Subject'] = subject msg['From'] = sender_email msg['To'] = receiver_email text = msg.as_string() else: cleanexit.quit() # Create a multipart message and set headers message = MIMEMultipart() message["From"] = sender_email message["To"] = receiver_email message["Subject"] = subject # Add body to email message.attach(MIMEText(body, "plain")) # Open file in binary mode with open(filename, "rb") as attachment: # Add file as application/octet-stream part = MIMEBase("application", "octet-stream") part.set_payload(attachment.read()) # Encode file in ASCII characters to send by email encoders.encode_base64(part) # Add header as key/value pair to attachment part part.add_header( "Content-Disposition", f"attachment; filename={filename}", ) # Add attachment to message and convert message to string message.attach(part) text = message.as_string() else: msg = MIMEText(body) msg['Subject'] = subject msg['From'] = sender_email msg['To'] = receiver_email text = msg.as_string() return text