PDA

View Full Version : How to get default email client to open on clicking 'email' button



rishiraj
2nd January 2009, 09:46
Hi all,
am working on an application created using Qt 3.3(on linux).
I need to do this--when I click on 'email' pushbutton,the default email client in the system should open up.(by the way,what's the default email client in linux,am not familiar with linux)
How to do it?I read that from Qt 4.2 onwards there's the Qdesktopservices class which can help.But in Qt 3.3,I guess I will have to use Qprocess.
Please guide me on how to implement it.
Thank you for your time.
Avi

wysota
2nd January 2009, 10:21
There is no default email client in Linux. You can open a default browser (which should be under the BROWSER environment variable) and point it to the mailto: protocol - it should try to open the default email client set in your system then.

rishiraj
2nd January 2009, 10:45
Hi,
sounds quite complicated(atleast for me)
:)
Can you give me some sample code.That would really help.
Thank you.

wysota
2nd January 2009, 10:49
QStringList slist;
slist+=getenv("BROWSER");
slist+="mailto:someaddr@somehost";
QProcess *proc = new QProcess(slist, this);
//...

rishiraj
2nd January 2009, 12:14
Hi again,
Tried implementing the code as follows.Please let me know if I made any mistakess.
QStringList slist;
slist +=getenv("BROWSER");
slist +="mailto:abc123@yahoo.com";
QProcess *proc=new QProcess(slist,this);
if(!proc->start())
{
QMessageBox::critical(0,"fatal error","can't open default email client");
exit(-1);
}
When I click on 'email' I get the message 'Can't open default.....".Does that mean that there's no email client installed in my system.I did a search on the system and came across something like an email client called 'Evolution' but,I don't think anyone's used it before or created a user account.......Is it possible to get some site like 'Hotmail' or yahoo to open instead of the default email client?
Please advice.

wysota
2nd January 2009, 13:04
It means the process didn't start but reasons for that may vary. Check what getenv("BROWSER") returns, maybe it is not set on a particular system.

You can open any site you want by providing a different address than mailto:something (like http://www.yourmailsiteaddress.com). But this will only work if the default browser is set (using the $BROWSER env variable).

rishiraj
5th January 2009, 04:59
Hi,
used a QMessageBox to get the value of getenv.It shows a blank.
Any suggestions on what else I could try?
Also,thanks for being patient and replying to my queries.

wysota
5th January 2009, 08:27
What happens if you write env|grep BROWSER in a terminal?

If BROWSER is empty then you need to ask the user to set his email client in the preferences of the application.