LiveCode LessonsHow To - LiveCode Mobile Tasks LiveCode Mobile TasksHow do I send an email from my mobile device?

How do I send an email from my mobile device?

In this lesson we will look at how to send an email from a LiveCode app.

revMail has now been expanded to work in the mobile space meaning that you can use revMail on your iOS device.

Create a basic stack with a field for the message and a button to send

Create a basic stack with a field for the message and a button to send

1) Create a new stack

2) Set its width to 320 and its height to 460

3) Drag on a button and call it "send"

4) Drag on a field and call it "message"

Add code to the send button

Add this code to the send button

on mouseUp

revMail "livecodemobile@runrev.com",,"Test message from my mobile device", field "Message"

end mouseUp

Parameter 1: The email address to receive the email

Parameter 2: Any cc email addresses

Parameter 3: Subject Line

Parameter 4: The message from our field

Test in the simulator

Test in the simulator

Your composed email will popup in the default device mail client ready for sending.

20 Comments

Grant Abt

How would you insert data from multiple fields into the email? I have an app with one field on one card and two fields on another card and would like to combine them all in one email.

Grant.

Barry Levine

Presumably this will work in the iPad. How about attaching a file to this outgoing eMail that would be something generated by my app?

Ben Beaumont

Hi Grant.

You can take the data from two fields and append it together. For example:

put field "message" & return & field "footer" into tEmailMessage

You can see from the line above that we are taking data from two fields and putting them together with a 'return' character in the middle. I've put the data into a new variable call tEmailMessage which I could then use with the mail command. I hope that helps.

Ben

Ben Beaumont

Hi Barry,

This will work with the iPad. I can also confirm that I have also added your request for a lesson on attaching files to emails. Keep an eye out on the lessons portal for that lesson.

Ben

Javier

I like this implementation. Will it work the same way on Android (and files can be attached?) ?

Ben Beaumont

Hi Javier,

Yes, you can compose email in the same manner on Android devices. If you want to attach files check out the mobileComposeMail command in the dictionary.

Warm regards,

Ben

uneu

Hello, how to omit email dialog and send message directly when button pressed w7o any further user action?

Jey Cole

Im just wondering, so far this seems to try to open the default email browser on my Mac. I want to send the email to a gmail account which is web based, is there a way of doing this?

Elanor Buchanan

Hi uneu

The revMail command sends emails by opening the email in the default mail client, there is no way to automatically send an email without the user confirming when using revMail.

If you want to do this one option is to use a server to send emails, you pass the information and the server sends out the email.

Here is an example of doing this using revServer

http://lessons.runrev.com/s/lessons/m/4070/l/8184-Sending-Emails-From-LiveCode-Server-Scripts

I hope that helps.

Kind regards

Elanor

Elanor Buchanan

Hi Jey

Yes, revMail will open your default email client. If you want to send an email via gmail you will need to have gmail set up as the default.

Kind regards

Elanor

uneu

How do I return to app automatically after sending the email?

Hanson Schmidt-Cornelius

Hi Uneu,

have a look at the following lesson for more information on how to send e-mails with LiveCode.

http://lessons.runrev.com/s/lessons/m/4069/l/29095-how-do-i-send-html-e-mails-with-attachments-in-ios

Once you send the e-mail, you are returned to your application.

Kind Regards,

Hanson

Nana

Is there a way to send automatically the email by pressing a button without opening the default email program on android?

Hanson Schmidt-Cornelius

Hi Nana,

no, it is not possible to send an e-mail from a device without opening an e-mail program for the user to confirm the e-mail first.

Kind Regards,

Hanson

Jessamy Goddard

Dear Hanson,

I have just written another app which sends an email perfectly on my device.
My question is this.
How do I close the mail after leaving the card?
I think this would help memory usage on my device.

Thankyou so much for all the help!!
With best wishes,
Jessamy

Hanson Schmidt-Cornelius

Hi Jessamy,

in order to prevent applications from sending spam, the user is prompted by the native e-mail application to confirm or reject sending the particular e-mail that was composed.

The user is returned to your LiveCode application, once the user accepted or rejects sending the e-mail. You have no control over how the external e-mail application is launched run or terminated from within LiveCode.

Kind Regards,

Hanson

Jessamy Goddard

Dear Hanson,

Thankyou!
You have answered my question.

Best wishes,
Jessamy

Daniel DuPont

For a Windows app, with Gmail as the default client, this just opens a browser (Chrome) with the defaults for Google. Clicking on mail it auto-signs me in (Because I am already signed in to the Gmail app), but does not generate the message.

Daniel DuPont

The link to send via server is useless. How does a mobile device pass the message to a server to be sent? Besides, apps send registration email all the time without user intervention. It's mandatory for apps with Push Notification. There must be a way to do this in LiveCode. Otherwise, it's a useless platform for mobile apps.

Hanson Schmidt-Cornelius

Hi Daniel,

revMail is used to interact with the user's specific mail client and can only pass the information through a separate client. It is possible that chrome, as a web browser, does not support the relevant arguments that pass the field data you populate in your application.

Another example of using an e-mail client is provided in the following lesson:
http://lessons.runrev.com/s/lessons/m/4071/l/13197
This may give you some more information on how to address the issue.

With regards to sending e-mails from mobile devices, the policy can vary, depending on the platform. For example if you use the mail client on an iOS device, then the user has final control over the content that is or is not sent.

If you do want to send automatic e-mails that are generated as a result of interacting with a device, then there are ways to do this by communicating with a remote server that is running an e-mail server.

Kind Regards,

Hanson

Add your comment

E-Mail me when someone replies to this comment