Gmail posting with OF

Hello there,

I’d like to send images from a computer (OSX) to a phone (android) and send mail (using the gmail API) with the image attached.

  • Sending image from a computer to a phone with OF is pretty straightforward.
  • Sending a mail with the gmail api in java is also straightforward.

Is there a way to send a mail with OF on an android platform ?

I want the user to enter his email and press enter. The mail with text and image attached must be automatically prepared based on the last image received.

Thanks for your thoughts

This is how you post a mail with gmail API

You need to do the job in the Java side of Android.

And I am not sure it worth to spend your time even in Java side, as the phone user can send any picture simply by tapping on it and selecting the option “share via email”.

Thanks Rancs


The picture is sent to an OF app running on the phone. I need this as I haven’t find a way to send an image from OF (running on my computer) to a java app running on the phone.

The share functions must be implemented in the OF app.
I don’t want “share functions” but a mail already prepared with specific text contents (“here is the picture taken from blablabla at the event blablabla …”)

Here is the list of the current native APIs provided by Android system:

#include <standard C library package name>
#include <jni.h>
#include <sys/system_properties.h>
#include <math.h>
#include <pthread.h>
#include <standard C++ library package name>
#include <android/log.h>
#include <zconf.h>
#include <zlib.h>
#include <dlfcn.h>
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <android/bitmap.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <EGL/eglplatform.h>
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Platform.h>
#include <SLES/OpenSLES_Android.h>
#include <SLES/OpenSLES_AndroidConfiguration.h>
#include <android/looper.h>
#include <android/input.h>
#include <android/keycodes.h>
#include <android/sensor.h>
#include <android/rect.h>
#include <android/window.h>
#include <android/native_window.h>
#include <android/native_window_jni.h>
#include <android/asset_manager.h>
#include <android/configuration.h>
#include <android/storage_manager.h>
#include <android/obb.h>
#include <android/native_activity.h>
#include <OMXAL/OpenMAXAL.h>
#include <OMXAL/OpenMAXAL_Platform.h>
#include <OMXAL/OpenMAXAL_Android.h>
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>

Unfortunately there is not a way to establish network connections in the native side for instant. You need to do the job in the Java side.

How do you send the image to the OF app running on the phone?

gmail just uses smtp, any of this addons should do:

i think mail utils doesn’s support TLS which might be needed for connecting to gmail but ofxSMTP does

1 Like

Hey taprik, did you try ofxSMTP? Does it work?

Thanks (again), I’ll try ofxSMTP

I guess ofxNetwork can send the image to the phone. I’ve used this addon many times from computer to computer, but not from computer to android phone.
Unfortunatly it’s big time now. I’ll give it a try in february.

Hey all, I’m happy to help you get ofxSMTP working if you run into problems. It has two modes – one for very simple emails – and one for attaching any MIME-type attachments that you like. One of the examples shows you how to send an image. It also works with secure smtp and has specific configuration files tested with gmail (which is why I originally wrote it). Sometime soon, I’ll refactor it a bit and add doxygen docs, but for the moment it should be working pretty well.

I manage to send image from a computer to a nexus.
You can find my source code below (this is the src folder in the android project). (4.5 KB)

I was inspired by a code of Theo Watson in this post

Actually, every time I send an image i get an error in the LogCat of Eclipse saying that it can’t create the client, but I got the image on the android !!

@bakercp : actually it takes time to send a big image (which was my purpose at the start) from the computer to the tablet. So, I have change my mind. I’ll post the mail from my computer, directly in the OF app, and use the tablet only as a tool for the user with a smallest image as a reference. I’ll try your addon :wink:

As an alternative, ofxHTTP offers some nice HTTP file and video / image streaming options that could be used on the either end. Good luck!

Actually when you’re using a gmail smtp server there is an issue.
I f you enter a recipient email address that is not a real email address the thread hang on and wait.
There is no problem with the smtp server of ovh, though.

To check if an email address got a chance to be a real one you can use

bool is_email(std::string const& address) {
    size_t at_index = address.find_first_of('@', 0);
    return at_index != std::string::npos
    && address.find_first_of('.', at_index) != std::string::npos;

Hi @taprik – is this a problem with ofxSMTP?

If so, can you leave an issue or a Pull Request there to add email validation?


Hi @bakercp

I’ll try to do that


1 Like

If some is reading this mail kindly give some sort of suggestion how should I fix this issue . Every four to five days my Gmail Account get blocked showing an temporary error and still I am confused to how to figure it out. If anybody know this solution kindly reply me in this thread.

When using ofxSMTP with Gmail, you’ll probably need to enable the “Less secure apps” mode.

You could also sign in with an app password

It’s a password for an app on one computer. You have to generate a password for every app on every computer. It works for me

@backercp Thanks!

1 Like