PDA

View Full Version : attaching file after opening default email client(Qt 4.4,Linux)



rishiraj
28th January 2009, 07:11
Hi,
need help in implementing this--
When I click 'email photo', the default email client should open up and the photo currently displayed in the gallery is automatically attached.

I have got the default email client to open (but,can't attach the photo) by using this--


QDesktopServices::openUrl(QUrl("mailto:?subject=&body=&attach="));

now if i give the path of the picture--


QDesktopServices::openUrl(QUrl("mailto:?subject=&body=&attach=/path/Desktop/buttons/button1.PNG"));

the pic gets attached.But,I don't want that (cause I will keep opening different picture files in the application so, filenames will keep changing).

When I view/open any picture ,I get it's path in a variable 'fileName' - -


fileName = QFileDialog::getOpenFileName(this,tr("Open File"), QDir::currentPath());


but, if i write --


QDesktopServices::openUrl(QUrl("mailto:?subject=&body=&attach=fileName"));

it doesn't work and shows "cannot attach 'fileName':no such file or directory."
But,if you use a QMessageBox inside the email() slot to print 'fileName', you get the correct filepath.

Can anyone suggest on what to change in the code to get the correct file attached?
Thanks in advance.

jpujolf
28th January 2009, 08:12
have you tested something like this ?



QDesktopServices::openUrl(QUrl("mailto:?subject=&body=&attach=" + filename));

rishiraj
28th January 2009, 08:29
Hi,
thanks a lot,your suggestion worked.

live_07
3rd October 2009, 19:04
Dear all,

I have got the default email client to open (but, can't attach the file in windows) by using this.

QString l_string = QFileDialog::getOpenFileName(this,tr("Open File"), QDir::currentPath());

QDesktopServices::openUrl(QUrl("mailto:test@test.com?subject=test&body="+l_string+"&attach=" + l_string));

Thanks in advance.

avipachar
22nd February 2012, 10:41
yes, it is not working on windows for me too.
Any suggestions?

jpujolf
22nd February 2012, 10:59
Have you checked that l_string contains no spaces ? Not tested, but you could try this :


QDesktopServices:openUrl(QUrl("mailto:test@test.com?subject=test&body="+l_string+"&attach=\"" + l_string + "\""));

avipachar
23rd February 2012, 05:55
Thanks for the suggestion.
But i am not ablw to attach a file even if i give the name of file.(VS2010)

Like this:
QDesktopServices::openUrl(QUrl("mailto:test@test.com?subject=test&body=hi&attach=agent_reporting.sln" ));

New mail is opened with subject and all but the file is not attached?

Please suggest why this is happening and what to do to attach the file?

Thanks
avinash

ChrisW67
24th February 2012, 05:33
On the Linux machine it was working by accident and not design.

The file is not attached because the mailto URL scheme (http://tools.ietf.org/html/rfc2368) does not specify "attach" as a special header like "body". You may specify any header defined in RFC 822 (http://tools.ietf.org/html/rfc822), which includes the only other header guaranteed to be supported... "subject". You could try building a mime encoded multi-part body and encoding that into the "body" along with Content-Type and MIME-Version headers. No guarantees though, because the headers are not guaranteed, and URLs generally have an implementation-defined upper limit on their size that is too small for a decent attachment.


Some Windows mail clients accept a non-standard "attachment" header.

vkn
22nd August 2012, 09:05
So does anybody succeeded in attaching file to the mail in Windows?

Can I have sample code that is working in Windows for file attachment. As I am facing the same problem in Windows.

Thanks in advance.

ChrisW67
23rd August 2012, 00:01
As explained above, you cannot reliably use mailto: links. You can try any of the Windows-specific methods;

Simple Mapi (does not support HTML tags in the body)
Extended Mapi (Does support HTML tags)
CMC (Common Messaging Calls) Is a non-platform specific. When it is used on Windows it will access the MAPI properties.
MAPI Activex
CDO (Collaboration Data Objects).
Automating Outlook
and probably others

I would guess that CDO is worth the most investigation.