Send Email from IOS and Andoid [Edit]

Hi
I am trying to make an app that will send a standard email from either an Android or an ISO mobile app.
The email will always go to the same address but the body will change.

Can anyone point me to any sample or other code.

Thanks

Edited by: Bob Spencer on Jan 19, 2014 9:23 AM
-1
Bob
1/19/2014 5:24:05 PM
embarcadero.delphi.firemonkey 4901 articles. 3 followers. Follow

5 Replies
7626 Views

Similar Articles

[PageSpeed] 29

For iOS Matthias Eissing wrote an example: http://blogs.embarcadero.com/matthiaseissing/2013/05/03/38707/
The Blogpost is in German, but at the bottom is the whole Code. And the body has to be UrlEncoded (for example for a Space u need to write %20).

For Android this Post is very interesting:
http://www.danieleteti.it/2013/09/26/sending-android-intents-from-delphi-part-1/
If you look for the real Android-Intent in Java, it should be possible to send an E-Mail via Delphi. (I made it to start the E-Mail App, but only without the E-Mail Adress...). Unfortunately I haven't the Code right here...
-1
Christian
1/20/2014 5:49:08 AM
> {quote:title=Christian Artinger wrote:}{quote}
> For iOS Matthias Eissing wrote an example: http://blogs.embarcadero.com/matthiaseissing/2013/05/03/38707/
> The Blogpost is in German, but at the bottom is the whole Code. And the body has to be UrlEncoded (for example for a Space u need to write %20).
> 
> For Android this Post is very interesting:
> http://www.danieleteti.it/2013/09/26/sending-android-intents-from-delphi-part-1/
> If you look for the real Android-Intent in Java, it should be possible to send an E-Mail via Delphi. (I made it to start the E-Mail App, but only without the E-Mail Adress...). Unfortunately I haven't the Code right here...

Thank you for that Christian,

I am trying to send email at the press of a button without the user having to do anything more. Its to allow a message to be sent with data silently regarding their membership details etc.

So, would I have to make two entire applications? One for Android and the other for IOS or is there a way to make one code and decide the platform later such as conditional compiling etc.

Im relatively new to this mobile app development so please forgive any stupid questions I make ask.

Thanks
1
Bob
1/20/2014 7:25:56 AM
This is what i use for emailing from Android and iOS i hope you find it useful.

function TMainForm.OpenURL(const URL: string;
  const DisplayError: Boolean): Boolean;
{$IFDEF ANDROID}
var Intent: JIntent;
begin
Intent:= TJIntent.JavaClass.init(TJIntent.Javaclass.ACTION_SENDTO);
Intent.setData(TJnet_Uri.JavaClass.parse(StringToJString(URL)));
Intent.putExtra(TJIntent.JavaClass.EXTRA_SUBJECT, StringToJString('This is the subject of the email'));
Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString('This is a text for the body of the email '+
                                                               'This continues in the same line as the above'+
                                                               sLineBreak+'This will go in a new line'));
try
  SharedActivity.startActivity(Intent);
  exit(true);
except
on e: Exception do
begin
    if DisplayError then ShowMessage('Error: ' + e.Message);
    exit(false);
end;
end;
end;
{$ELSE}
{$IFDEF IOS}
var NSU: NSUrl;
begin
  NSU := StrToNSUrl(TIdURI.URLEncode(URL));
  if SharedApplication.canOpenURL(NSU) then begin
    exit(SharedApplication.openUrl(NSU))
    end
  else
  begin
    if DisplayError then
      ShowMessage('Error: Opening "' + URL + '" not supported.');
    exit(false);
  end;
end;
{$ELSE}
begin
  raise Exception.Create('Not supported!');
end;

{$ENDIF IOS}
{$ENDIF ANDROID}

And the code for the OpenUrl function is this
{$IFDEF ANDROID}
OpenURL('mailto:ASDADA@something.com');
{$ELSE}
{$IFDEF IOS}
OpenURL('mailto://ASDADA@something.com?Subject=This is the subject'+
                                    '&Body=This is the text of the body'+
                                    'And this will change line \n '+
                                    'This is written in a new line');
{$ENDIF IOS}
{$ENDIF ANDROID}


> {quote:title=Bob Spencer wrote:}{quote}
> > {quote:title=Christian Artinger wrote:}{quote}
> > For iOS Matthias Eissing wrote an example: http://blogs.embarcadero.com/matthiaseissing/2013/05/03/38707/
> > The Blogpost is in German, but at the bottom is the whole Code. And the body has to be UrlEncoded (for example for a Space u need to write %20).
> > 
> > For Android this Post is very interesting:
> > http://www.danieleteti.it/2013/09/26/sending-android-intents-from-delphi-part-1/
> > If you look for the real Android-Intent in Java, it should be possible to send an E-Mail via Delphi. (I made it to start the E-Mail App, but only without the E-Mail Adress...). Unfortunately I haven't the Code right here...
> 
> Thank you for that Christian,
> 
> I am trying to send email at the press of a button without the user having to do anything more. Its to allow a message to be sent with data silently regarding their membership details etc.
> 
> So, would I have to make two entire applications? One for Android and the other for IOS or is there a way to make one code and decide the platform later such as conditional compiling etc.
> 
> Im relatively new to this mobile app development so please forgive any stupid questions I make ask.
> 
> Thanks
1
Asder
1/20/2014 7:42:57 AM
I don't know if it works to send an E-Mail without user interaction (afaik the E-Mail Client always Opens and you have to press "Send").

You can use the same Project for Android and iOS. You have to use defines for that:

{code}
{$IF DEFINED(ANDROID)}
// Android Code here
{$ENDIF}

{$IF DEFINED(iOS)}
// iOS Code here
{$ENDIF}

{$IF DEFINED(iOS) or DEFINED(ANDROID)}
// iOS or Android Code here
{$ENDIF}
{code}
1
Christian
1/20/2014 7:45:35 AM
> {quote:title=Christian Artinger wrote:}{quote}
> I don't know if it works to send an E-Mail without user interaction (afaik the E-Mail Client always Opens and you have to press "Send").
> 
> You can use the same Project for Android and iOS. You have to use defines for that:

Nah i doubt you can do that. It would be kinda dangerous if you could do that i think. What exactly do you want to achieve? You could do some logging from your datasnap server or something else to record activity, or make a sharing function to share information that gets stored in a log.
-2
Asder
1/23/2014 7:15:18 AM
Reply:

Web resources about - Send Email from IOS and Andoid [Edit] - embarcadero.delphi.firemonkey

Asus may be cooking up another low-cost Andoid tablet
New benchmarks hint at a budget-minded Android 4.1 tablet with a 1GHz processor and a 1024×600 display.

Samsung set to unveil colorful Andoid tablets
Samsung Electronics has sent out invitations to a June 12 event in New York, at which the company is expected to launch new Android tablets. ...

Like Google Voice But Live Outside The US? Then Try VoxSci's New iO6/Andoid App
Google Voice remains a pretty useful service if you want your voice mails turned into text messages. However, it’s ability to do so accurately ...

Andoid - Tags - TechRadar
Andoid news and reviews on TechRadar

Lenovo ThinkVision 28 Smart 4K Andoid Display
... it is a complete instant-on experience. (more…) Follow: Computers , CES , CES 2014 , Lenovo , monitors , Lenovo ThinkVision 28 Smart 4K Andoid ...

TruckSpotting - CrunchBase Profile
TruckSpotting uses real time GPS to track Food Trucks and display their location relative to the user via IPhone and

Goodreads.com - LinkedIn
LinkedIn strengthens and extends your existing network of trusted contacts. LinkedIn is a networking tool that helps you discover inside connections ...

Android - MobiCity Australia
Online smartphone store selling the best new, unlocked mobile phones. Review, compare & buy online. Fast delivery, full Australian warranty ...

About Us
Amitech Business Solutions, Creative Technology Startup ventures , Innovative IT company of India, allevents.in trendround

Aliexpress.com : Buy MK806 Dual Core Mini PC Rockchip RK3066 1.6GHz 1GB RAM 4GB Android 4.1 with 3.5mm ...
... Shipping MK802 IIIs,High Quality Mk806 mini pc,China MK802 III Dual Core Mini PC Suppliers, Cheap MK802 III Dual Core android PC from Andoid ...

Resources last updated: 1/16/2016 8:48:47 AM