email in iOS

I tried searching the forums, and had a quick scan through the language reference guide, so tried to find the answer before posting here!

I have written my first iOS app with Xojo, but have reached a small road block.

How do I pass information to the email program in iOS? In my app I want to give the user the option to send information created by my app by email, but can’t see a way to pass information to other iOS application that are part of the core iOS.

any help would be appreciated.

Darren

Give me an hour or two and I can implement this in declares.

Unless XOJO did something magic… Email Code will NOT work in the simulator… it will compile, just not send emails

You are correct, this will only work in a built app deployed to a phone. If someone can test it to make sure it works that would be great. When you are testing please press the Send Message button twice. If this behaves similar to the camera then I think I will need to create a small workaround so that more than one email can be sent consecutively without restarting the app.

[quote=152579:@Jason King]You are correct, this will only work in a built app deployed to a phone. If someone can test it to make sure it works that would be great. When you are testing please press the Send Message button twice. If this behaves similar to the camera then I think I will need to create a small workaround so that more than one email can be sent consecutively without restarting the app.

https://www.dropbox.com/s/5cksy1cj3cg7zc1/mail%20view%20.xojo_binary_project?dl=0[/quote]

I get “Email is not available” :frowning:

Did you deploy to a phone? And do you have email set up on that phone? Both are required for it to work.

Yes to both.

Weird. canSendMail must be returning false even though you have email set up…

Do you have Exchange Active Sync for email? Or is it possible that the email certificate you have prevents you from sending emails from an app other than Mail? Those appear to be two reasons that can cause this to happen.

I use GMail which I set up in the simplest of ways, and do not even see what you mean by email certificate, or where it is set up. I receive and send email on and from my iPhone using the Mail default application.

This demonstrate a possible issue with sending email within an ioS device. In Mac OS X, you can use SMTPSocket with any server. Is that not possible here ?

Alternative way, but it’s not a best solution.

I use iOSHTMLViewer with LoadURL method.
Example code :
WebViewer.LoadURL(“mailto:someone@example.com?cc=someoneelse@example.com&bcc=andsomeoneelse@example.com&subject=Summer%20Party&body=You%20are%20invited%20to%20a%20big%20summer%20party!”)

That’s launch mail client on IOS device.

To avoid needing a HTML Viewer as that would be overkill to pop a mailto: url, you can borrow the ShowURL declare from the docs: http://xojo.helpdocsonline.com/declare

Why it’s a declare and not built in, I don’t really know.

[quote=152627:@Franck Danard]Alternative way, but it’s not a best solution.

I use iOSHTMLViewer with LoadURL method.
Example code :
WebViewer.LoadURL(“mailto:someone@example.com?cc=someoneelse@example.com&bcc=andsomeoneelse@example.com&subject=Summer%20Party&body=You%20are%20invited%20to%20a%20big%20summer%20party!”)

That’s launch mail client on IOS device.[/quote]

Yeah. I thought about that. But figured the OP may have wanted to do that within his app.

[quote=152622:@Michel Bujardet]I use GMail which I set up in the simplest of ways, and do not even see what you mean by email certificate, or where it is set up. I receive and send email on and from my iPhone using the Mail default application.

This demonstrate a possible issue with sending email within an ioS device. In Mac OS X, you can use SMTPSocket with any server. Is that not possible here ?[/quote]
Well a SMTPSocket or similar would probably work, but the “apple approved” method is using the MFMailComposeViewController class. I’m not sure why it is failing…

I also always get False returned from canSendMail on my iPhone 6. I had looked into this a bit a couple weeks ago, but never figured out why it always returns False.

Thanks for the additional data point. Maybe something is broken in iOS 8?

thanks for all the activity in this thread, I am unable to use the htmlviewer method as I am not sending the email to pre determined email address. my app basically creates a file that the user would then be able to email on to someone, that is the roadblock I have hit. its how to (if possible) open the mail app from my app, with the subject and body of the email filled out, and the attachment already there, just waiting for the user to enter an email address to send it to and hit send.

You could have the user fill a form with all necessary information, then showURL the result so he will find that in the Mail program.

Just try the above posted URL by Frank Danard in any browser and you will see that it works on a Mac as well. It does exactly what you describe.

StackOverflow has a thread on adding an attachment to iOS email using MFMailComposeViewController. One of the declare gurus here would have to translate this into working Xojo code.

In that thread, there is a comment that attachments are not a part of the mailto url scheme.

[quote=152831:@Scott Siegrist]StackOverflow has a thread on adding an attachment to iOS email using MFMailComposeViewController. One of the declare gurus here would have to translate this into working Xojo code.

In that thread, there is a comment that attachments are not a part of the mailto url scheme.[/quote]
That’s what I did :stuck_out_tongue:
It doesn’t seem to work though because the canSendMail function always returns false, so the view cannot be presented to the user.