Enter email and sending emails with attachment...How?

Hi guys!
There is such a problem, I need to make an app where you could take a picture, enter their e-mail and immediately send this photo to their emails.
I found the virtual keyboard in touchdesigner, but not yet understand how to make a panel for insertion of mail and how to send a mail with an attachment?

Please tell me how it can be implemented? :unamused:

Thanks in advance!

Hey,

you would probably want to use the python smtp lib for sending email. There is a good explanation for sending attachments here.

Usually you would use a Field COMP and a Button COMP to create a file browser. On the Button COMP run a PanelExecute DAT and use the ui.chooseFile() method (described here) to select a file.

A Text TOP as a Panel COMP background should work for the email content.

There is a Tutorial here that might be helpful.

Best
Markus

I use this code but it not works =(
What wrong with this?

[code]import smtplib
from smtplib import SMTP_SSL
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import encoders
import os

filepath = ā€˜1.jpgā€™
fromaddr = ā€œname@gmail.comā€
toaddr = ā€œname2@gmail.comā€
password = ā€˜********ā€™
mail_adr = ā€˜smtp.gmail.comā€™
mail_port = 587

Compose attachment

part = MIMEBase(ā€˜applicationā€™, ā€œoctet-streamā€)
part.set_payload(open(filepath, ā€œrbā€).read())
encoders.encode_base64(part)
part.add_header(ā€˜Content-Dispositionā€™, ā€œattachment; filename= %sā€ % os.path.basename(filepath))

Compose message

msg = MIMEMultipart()
msg[ā€˜Fromā€™] = fromaddr
msg[ā€˜Toā€™] = toaddr
msg.attach(part)

Send mail

smtp = SMTP_SSL()
smtp.set_debuglevel(1)
smtp.connect(mail_adr, mail_port)
smtp.login(fromaddr, password)
smtp.sendmail(fromaddr, toaddr, msg.as_string())
smtp.quit()[/code]

and error

connect: ('smtp.gmail.com', 587) connect: ('smtp.gmail.com', 587) Traceback (most recent call last): File "C:/Users/Oleg/Desktop/111.py", line 31, in <module> smtp.connect(mail_adr, mail_port) File "C:\Users\Oleg\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 335, in connect self.sock = self._get_socket(host, port, self.timeout) File "C:\Users\Oleg\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 1037, in _get_socket server_hostname=self._host) File "C:\Users\Oleg\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 401, in wrap_socket _context=self, _session=session) File "C:\Users\Oleg\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 808, in __init__ self.do_handshake() File "C:\Users\Oleg\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 1061, in do_handshake self._sslobj.do_handshake() File "C:\Users\Oleg\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 683, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:749)

Helloā€¦

I tried this options but doesnĀ“t workā€¦

Any other idea?

Regards!

hi touch community
are there any news regarding sending an email with attachment out of touch?
i have a job in front of me where it would be necessary to have this possibility!

thank you in advance!
luka

Iā€™m sure you could get there with Python. Does something like this help you get started?

medium.freecodecamp.org/send-em ā€¦ fcea9df63f

hi
thank you for the link, i will look into it, but im quite sure it will bring me to the edge of my phyton knowledge! :confused: learn learn learnā€¦
luka

If itā€™s a job, you can always pay someone to help you with it. :laughing:

Otherwise Iā€™d start small with email without attachments, which I believe you can do with just the built in logging module (Iā€™ve sent emails from TouchDesigner and believe I used logging), then from there you can start switching to other libraries and adding more features till it works.

We have a full TD component built out that handles emails with full HTML and plain text formatting, attachments, and pretty robust error capture. I would need to extract it from the project file it was built for to be able to share it but itā€™s definitely very doable in python.

FYI if you send a lot of emails (especially with attachments) from a no-name server, or you automate them through a gmail account, you could get yourself blacklisted.

Iā€™d recommend using a service like Mailgun or some such, using a paid account, and giving them a heads-up what youā€™re doing so they donā€™t shut you off midway through your project for suspicious activity.

Hey guys,

So I figured out how to send emails from Python installed on my mac (3.6), but when I run this exact same code in Touch the error ā€œNo SSL support included in this Pythonā€ occurs when the code gets to the starttls() attribute - which puzzles me because TD imports smtp just fine and i thought SSL support was built into smtp. Anyways hope this helps someone!

P.S. If you want to send emails via python from a gmail acct you need to make sure you gmail acct allows access from less secure apps or else your code will yeild an authentication error

python >>> mail.starttls() Traceback (most recent call last): File "<Textport>", line 1, in <module> File "/Applications/TouchDesigner099.app/Contents/Frameworks/Python.framework/Versions/3.5/lib/python3.5/smtplib.py", line 755, in starttls raise RuntimeError("No SSL support included in this Python") RuntimeError: No SSL support included in this Python

---------send email via python 3.6---------

[code]import smtplib #built into vanilla python installation

content = ā€˜ex email stuff from meā€™ #the body of the email

mail = smtplib.SMTP(ā€˜smtp.gmail.comā€™,587) #the smtp mailserver that youā€™re sending to and the port associated with it gmail uses 465 & 587

mail.ehlo() #identify yourself to server via .ehlo for ESMTP (extended smtp) or .helo for SMTP

mail.starttls() #start tls mode .tls = transport layer security any smtp comman coming after this will be encrypted

mail.login(ā€˜myemail@gmail.comā€™, ā€˜mypasswordā€™) #login to acct

mail.sendmail(ā€˜from emailā€™,ā€˜to emailā€™, content) # send email, from email = same email you logged into

mail.close() # once email is sent close connection[/code]

Sorry for delay, i forgot this post :frowning:

This is an example with the solution for gmail and your own email with attachment fileā€¦

It will work for any email and any file, just fill the data table DAT in blue with your data and boom!!!

Also remember that if you are sending big file attachment need to make delay between load data and send in order to give time to your email server (any) to upload your file, and it depend about your internet connection.

send email with attachment.toe (5.25 KB)

Enjoy!

Javo

Hi, that looks very promising,
but when i try with my gmail i get all those errors:

Exception in thread Thread-6: Traceback (most recent call last): File "C:\Program Files\Derivative\TouchDesigner099\bin\lib\threading.py", line 914, in _bootstrap_inner self.run() File "C:\Program Files\Derivative\TouchDesigner099\bin\lib\threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "/container1/chopexec", line 44, in mail File "C:\Program Files\Derivative\TouchDesigner099\bin\lib\smtplib.py", line 729, in login raise last_exception File "C:\Program Files\Derivative\TouchDesigner099\bin\lib\smtplib.py", line 720, in login initial_response_ok=initial_response_ok) File "C:\Program Files\Derivative\TouchDesigner099\bin\lib\smtplib.py", line 641, in auth raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu2\n5.7.14 JoqSbB6LzRSuitSYfvrGjAj2-_0isayffzJO2H87KDp6YLSswB12VVqCNqrqM2F-CojT8V\n5.7.14 Dbn-frtMywBkCPK_rnQvboTxv0C-fOqnJiV9q6uVc4y-1rDelAHo1uOEpVb3wS0BooANpP\n5.7.14 8aTanazKL3j2NXviPcvoTqNrwvw_LSk2PjOl1vqWO8S5uoP5KbJHEA8dvCqCDqURApNkxe\n5.7.14 HD1QvB1dCeylkq8-tvt5uYGGToR2LAov1bjLV7xIWh7mImZGc7mq3dPpU38ifLxlpAslDN\n5.7.14 eiq_nsbsUMeHyKYN9AIrtHKQ9tgAN7aKAw0fyUMZwt-13LM4VBJS9JJOIeiNNhtmu4Vcvr\n5.7.14 oN4mDVK6hyZjSgl6WSUsreV2V6P9WUIJCDZ8lQZiwayRa7qEdTL9uIbt1gUlA_9ECSnkcD\n5.7.14 67J-FD2P_Q7dVwFghXzJmgmXqGudsLkPiO8aAtmmPIhiY9ubXU6FiUJ-n2KFyYzU8EUwfU\n5.7.14 IrRI4> Please log in via your web browser and then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 q135-v6sm3940743wmd.4 - gsmtp')

Any idea what they mean? Or how I can fix them ?

thnak you
Stefan

I was just trying to get this to work but never got an email.
Iā€™ve changed my gmail settings to allow for less secure apps and double checked my credentials. Iā€™ve also tried a print statement at the end of the code which does print with zero errors.
It should work but it isnā€™t currentlyā€¦any suggestions? Thank you for sharing.

hello and sorry for delay answering.

@MXZEHN it seem you have problem with python library ā€œsmtplibā€ make sure you have library installed and site-packages added to python preferences.

@WAMSAY you need to allow gmail to be managed from third party email apps, im trying to find a link in english to configure it but i cant now, search in google and then it will work

good luck both

Javo

Thank you Javo!

The toggle is located in security under apps with account access in gmail at the very bottom.

Just sent my first banana :slight_smile:

Banana yeah!! :slight_smile: