Python Forum
[Solved]Help Displaying Emails properly via Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved]Help Displaying Emails properly via Python
#5
I got it to work.

Apparently he message body didn't like being inside the function because it was tabbed out so I put it at the top of my code as a variable so I didn't have to tab it out and now it works as it should and the emails display properly.

This displays it properly.
#-------------------------------------------------------------------------------------
#                                Define Variables
#-------------------------------------------------------------------------------------
console = Console(width=100) 

#E-mail display format for E-Mail Function
emailFormat = """\
From: "Baxter"
Subject: Alert!

""" 
#-------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------
#                                E-Mail Function
#-------------------------------------------------------------------------------------
def sendEmail():
    #Tutorial Link: https://www.abstractapi.com/guides/sending-email-with-python
    #Define the transport variables
    ctx = ssl.create_default_context()
    password = "12345"
    sender = "[email protected]" 

    autoTypeAnimation('Who should I send the E-mail to?')
    receiver = UserInput()

    autoTypeAnimation('What should I say?')
    msg = UserInput()

    #Preview the E-mail
    print("\n[green]Baxter: [/green]")
    print(emailFormat + msg + "\n")
    
    #Send Email
    try:
        with smtplib.SMTP_SSL("smtp.gmail.com", port=465, context=ctx) as server:
            server.login(sender, password)
            server.sendmail(sender, receiver, emailFormat + msg)
            autoTypeAnimation('E-mail sent')
    except:
        autoTypeAnimation('E-mail failed to send')
#-------------------------------------------------------------------------------------
Reply


Messages In This Thread
RE: Help Displaying Emails properly via Python - by Extra - Sep-28-2022, 09:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel isnt working properly after python function is started IchNar 3 300 May-02-2024, 10:27 AM
Last Post: lillydalson
  How do I properly implement restarting a multithreaded python application? MrFentazis 1 647 Jul-17-2023, 09:10 PM
Last Post: JamesSmith
  Sending Emails on Autopilot Gyga_Hawk 3 1,726 Mar-15-2022, 08:20 AM
Last Post: Larz60+
  Mark outlook emails as read using Python! shane88 2 6,646 Feb-24-2022, 11:19 PM
Last Post: Pedroski55
  Trying out the parsing/reading of emails from my outlook cubangt 0 6,242 Jan-12-2022, 08:59 PM
Last Post: cubangt
  reading shared outlook emails zarize 0 2,481 Mar-03-2020, 01:47 PM
Last Post: zarize
  Python Library for Reading POP Emails? bmccollum 1 3,677 Jan-06-2020, 06:37 PM
Last Post: micseydel
  Read in trades from emails semantina 2 2,138 Nov-06-2019, 06:12 PM
Last Post: semantina
  In Visual Studio Python is not properly installed jalea148 4 3,134 Sep-26-2019, 12:31 PM
Last Post: snippsat
  Python 2.7.13 Issue Reading .txt files Properly username1145 3 2,560 Mar-24-2019, 03:08 PM
Last Post: username1145

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020