Example #1
0
    def send(self):
        self.label_status.config(text="Sending...")
        address = self.entry_email.get()

        if not re.match(r"[^@]+@[^@]+\.[^@]+", address):  # basic loose regex
            self.label_status.config(
                text="The entered email is syntactically invalid, try again.")
        else:
            try:
                msg = MIMEMultipart()

                msg["From"] = SMTP_USER
                msg["To"] = address
                msg["Subject"] = "Here's your silhouette!"
                msg.preamble = "Here's your silhouette"

                body = MIMEText('''<h1>Here's your silhouette</h1>
        <p>Thank you for using Pilhouette!</p>
        <p>You can find your silhouette attached to this email.</p>
        <hr />
        <img src="http://brightonfoodfestival.com/wp-content/uploads/2013/07/regency_town_house.jpg"/>''',
                                _subtype='html')
                msg.attach(body)

                with open("temp/processed/" + self.filename, "rb") as f:
                    s_data = f.read()
                s = MIMEImage(s_data)
                s.add_header("Content-Disposition",
                             "attachment",
                             filename="silhouette.png")
                msg.attach(s)

                with smtplib.SMTP(SMTP_SERVER) as s:
                    #s.ehlo()
                    s.starttls()
                    s.login(SMTP_USER, SMTP_PASS)
                    s.send_message(msg)

                self.controller.success(address)
            except:
                self.label_status.config(text="An error occurred, try again.")