How to send email through processing?

Hello,

I have a sketch that I have a bunch of error checking in, and if a flag is set, I want to be notified via email. I have searched for a while, and every link comes up dead from 2016 and before. I have not found any topics related to this since. There is one for Mac, but I have a PC, and there is also another one that you have to sign up for a temboo acount (https://temboo.com/processing/send-email) but I would rather not use that app as I have never heard of it. I am hoping there is some library or command that I can log into a gmail account, and have that send an email to my main account. Has anyone done this before?

Thank you.

1 Like

Processing is built on top of Java, so if you can’t find a Processing library that does what you want, you can always look for a Java solution.

Googling “java send email” or “java send gmail” returns a ton of results that seem pretty promising.

3 Likes

Looks like Shifftman made an example back in 2007 - https://shiffman.net/blog/email/java/p5/processing.org/2007/11/13/e-mail-processing/,

But the JavaMail library is out of date. Here is the latest version - https://javaee.github.io/javamail/#Download_JavaMail_Release

Good luck, hope this helps :slight_smile:

1 Like

Keep in mind when using gmail, you have to lower some security setting. I forgot what it was named.

I have tried multiple examples, and the one linked from 2007 is my best bet so far, but every time I try to run it, I get “Cannot find a class or type named “Properties””

Has anyone else tried this example? I also updated the javamail library. I will try going through the readme as well.

What is your underlying operating system?

Are you trying to send it via an account you control on a remote server, e.g. a POP3 or IMAP account? Or are you trying to use your computer as a mail server?

Perhaps (untested) you could also use a service to generate the message directly – for example, IFTTT.

If you already have a full mail server running on your machine, you could also use exec() or run() to send the mail from the command line. However a public url to a third-party service will be more robust in that your sketch will be able to send the message no matter what computer it is running on as long as it has an internet connection – no changes to security settings etc needed. By contrast, trying to originate mail from your own mail server can have a lot of points of failure depending on your internet connection / service.

I am running windows 10 on a pc.
I am trying to run processing to send an email if “X” condition has been met by my program.
I don’t know much about the internet processes I am trying to access.

So I finally got the code to verify and run, but I had to add

import java.lang.;
import java.util.
;

to the code, and update all the libraries.

That being said, I could not log into google because google blocked me from logging into a test gmail account I made for my purposes.

The full errors I got are

authenticating. .
javax.mail.AuthenticationFailedException: [AUTH] Web login required: Can't sign in to your Google Account - Gmail Help
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:215)
at javax.mail.Service.connect(Service.java:388)
at javax.mail.Service.connect(Service.java:246)
at javax.mail.Service.connect(Service.java:195)
at Email.checkMail(Email.java:117)
at Email.setup(Email.java:59)
at processing.core.PApplet.handleDraw(PApplet.java:2404)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1557)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
com.sun.mail.util.MailConnectException: Couldn’t connect to host, port: localhost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2209)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
at javax.mail.Service.connect(Service.java:366)
at javax.mail.Service.connect(Service.java:246)
at javax.mail.Service.connect(Service.java:195)
at javax.mail.Transport.send0(Transport.java:254)
at javax.mail.Transport.send(Transport.java:124)
at Email.sendMail(Email.java:179)
at Email.setup(Email.java:62)
at processing.core.PApplet.handleDraw(PApplet.java:2404)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1557)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:359)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2175)
… 11 more

In addition, I got an email from google saying that they blocked somebody from logging into my account using my same password. I can’t find anywhere on google how to allow this connection. It keeps asking me to create a google API console, and this is currently beyond me. Is there just some sort of permissions button I can turn off to allow java log in?

Thank you again for your help.

Edit: I found the allow less secure apps page here

But I am still running into the same errors.

Edit2: Got it working!!!
Had to allow less secure apps on the website above, AND AND AND another less secure app access here
https://myaccount.google.com/security

Works great! Thanks for everyones help!

1 Like

Hey, I know it’s been a while, but could you share some skeleton example of the code you used that works? Also, how to setup the sketch? I’m new to using straight-up Java in Processing and could use a couple of hand-holds. My sketch needs to send an email with an attached file when a user inputs their email address into a text field. I got the text field email acquisition figured out, but any further shortcuts to getting all the pieces in the right place will be nice.