Recent

Author Topic: Open default e-mail client, with subject and body  (Read 25635 times)

Furby

  • New member
  • *
  • Posts: 8
Open default e-mail client, with subject and body
« on: February 23, 2011, 11:10:13 pm »
Is it possible open a default e-mail client and automatically put there a e-mail address, subject and body of e-mail, after for example clicking on a button?

I click on button, my e-mail client will open with this already in there, like in the attached picture.


bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: Open default e-mail client, with subject and body
« Reply #1 on: February 24, 2011, 07:50:02 am »
I made it.

You must create a file batch (for example MyBatchFile.bat) and then, with TProcess, call the file batch using this syntax:

Code: [Select]
start MyBatchFile.bat
Here explain how create the file batch: http://www.robvanderwoude.com/email.php

Hi, Mario

Furby

  • New member
  • *
  • Posts: 8
Re: Open default e-mail client, with subject and body
« Reply #2 on: February 24, 2011, 11:16:56 am »
Okay, that could work, thanks.

Does anyone know how to do this in Linux/OSX?

kellemes

  • New Member
  • *
  • Posts: 13
Re: Open default e-mail client, with subject and body
« Reply #3 on: February 24, 2011, 05:17:36 pm »
Does anyone know how to do this in Linux/OSX?

Don't know about OSX.

(afaik) I don't see an easy way to do this since you have a lot of desktop environments available that all provide there own method of setting default apps. Seems to be a big task to first check what dm is running, then check for the default mailclient (howto depends on dm) and then run the client with it's own specific parameters..
Personally (using Linux) I don't even have a default-mailclient since I'm only using Gmail these days and others may use something console based like Mutt.

Why not send your mail from code? I'm just starting Lazarus but there surely must be some library then handles that?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Open default e-mail client, with subject and body
« Reply #4 on: February 24, 2011, 06:06:24 pm »
This works here on OpenSuse:
Code: Pascal  [Select][+][-]
  1. uses LCLIntf;
  2. ...
  3. OpenURL('mailto:theo@test.com?subject=test&body=Hello World');  
 

Newmann

  • Jr. Member
  • **
  • Posts: 62
Re: Open default e-mail client, with subject and body
« Reply #5 on: February 24, 2011, 06:35:18 pm »
This works here on OpenSuse:
Code: Pascal  [Select][+][-]
  1. uses LCLIntf;
  2. ...
  3. OpenURL('mailto:theo@test.com?subject=test&body=Hello World');  
 

Is it possible to attach a file with this method?
Lazarus 1.0.14
FPC 2.6.0
Win7 Pro 64bit/Win XP Pro 32bit

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Open default e-mail client, with subject and body
« Reply #6 on: February 24, 2011, 07:36:10 pm »
Is it possible to attach a file with this method?

Who knows. Try this:
 OpenURL('mailto:theo@test.com?subject=test&body=Hello World&attachment=/home/user/test.txt');

Btw. the parameters have nothing to do with Lazarus.

Furby

  • New member
  • *
  • Posts: 8
Re: Open default e-mail client, with subject and body
« Reply #7 on: February 24, 2011, 11:40:38 pm »
This works here on OpenSuse:
Code: Pascal  [Select][+][-]
  1. uses LCLIntf;
  2. ...
  3. OpenURL('mailto:theo@test.com?subject=test&body=Hello World');  
 

<3

This is great I don't have to make different solutions for all OS.. thanks.

Silly question with what sign I do "next line" I am now confused which one to use.. =)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Open default e-mail client, with subject and body
« Reply #8 on: February 25, 2011, 12:25:14 am »
As I said, this has nothing to do with Freepascal or Lazarus.

http://lmgtfy.com/?q=mailto+Syntax&l=1

Furby

  • New member
  • *
  • Posts: 8
Re: Open default e-mail client, with subject and body
« Reply #9 on: February 25, 2011, 02:07:34 pm »
Thank you again.  ;)

patyi

  • Full Member
  • ***
  • Posts: 168
Re: Open default e-mail client, with subject and body
« Reply #10 on: February 06, 2014, 06:18:19 pm »
Hi all !

I'm experimenting a bit and found command below is working perfectly on XUbuntu 13.10 i386, Lazarus 1.3 SVN, FPC 2.6.3 SVN.  :D

OpenURL('email@adress.com?'+
                'subject=hello&'+
                'body=Hello World&'+
                'attach='+FDataMod.SaveDlg.FileName);

(note that the Attachment is added !)

Newmann

  • Jr. Member
  • **
  • Posts: 62
Re: Open default e-mail client, with subject and body
« Reply #11 on: February 07, 2014, 07:45:42 am »
Tested it in Windows...not working  :(
Lazarus 1.0.14
FPC 2.6.0
Win7 Pro 64bit/Win XP Pro 32bit

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: Open default e-mail client, with subject and body
« Reply #12 on: February 07, 2014, 08:24:36 am »
Hi all !

I'm experimenting a bit and found command below is working perfectly on XUbuntu 13.10 i386, Lazarus 1.3 SVN, FPC 2.6.3 SVN.  :D

OpenURL('email@adress.com?'+
                'subject=hello&'+
                'body=Hello World&'+
                'attach='+FDataMod.SaveDlg.FileName);

(note that the Attachment is added !)

How is declared "FDataMod" ?

Thanks, Mario

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Open default e-mail client, with subject and body
« Reply #13 on: February 07, 2014, 08:38:37 am »
OpenURL('email@adress.com?'+
                'subject=hello&'+
                'body=Hello World&'+
                'attach='+FDataMod.SaveDlg.FileName);

(note that the Attachment is added !)

How is declared "FDataMod" ?

I suspect not important, though probably TDataModule.  SaveDlg will be a TSaveDialog, and Filename will be a string.  It's the last that you need, a simple string containing a filename. 

(Note: I'm only answering the question about FDataMod.  I'll be surprised if this call works on Windows without the mailto: prefix, but haven't checked)
« Last Edit: February 07, 2014, 08:43:48 am by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

 

TinyPortal © 2005-2018