View Full Version : [Solved] How to open default email client with attachment
Laethnes
2011-04-27, 07:10
I know similar question is asked like thousand times, but I couldn't find clear answer. So, is there a way how to open default email client with to send email with attachment? I mean, something like "QDesktopServices::openUrl(QUrl("mailto:?subject=Test"));" but I need attach a file and adding "attach" or "attachment" is not standard way to use "mailto" and it does not work on N900 maemo default email client.
I know about possibility write own client connecting to SMTP server, but I would love to avoid it...
Mike Fila
2011-04-27, 07:20
I dont know if I understand what you are trying to do but if i got it right you can use filebox. You can select the file or files you need then hold for along press, choose share, and modests opens to a blank email with all the attachments there.
to select multiple files you have to enable select multiple files by going into filebox's settings
Laethnes
2011-04-27, 07:48
I apologize I didn't give exact information.
I'm working on some application (language is C++, mainly in Qt library) which generates some files (usually hidden from user) and we want to give the user possibility to send it. I already implement sending by bluetooth and now we want email; user will select item in our app and from menu select "send via email" and there we want to default email client to appear (pop up) composing new email with a file in attachment. User will set receiver and can write message and send it. That's my problem.
EDIT:
To give example, I would like to do something like this:
#include <QDesktopServices>
void MyClass::slotSendFileViaEmail(const int itemId)
{
const QString fileName = getFileFromItemId(itemId);
// Logic in program checks existence of file somewhere else
// and this slot should be called only in case it exists.
Q_ASSERT(QFileInfo(fileName).exists());
// Version 1
QDesktopServices::openUrl(QUrl("mailto:?subject=File from our app.&attach=" + fileName));
// Version 2
QDesktopServices::openUrl(QUrl("mailto:?subject=File from our app.&attachment=" + fileName));
}
or something like this
#include <QMessage>
#include <QMessageService>
#include <QFileInfo>
QTM_USE_NAMESPACE;
void MyClass::slotSendFileViaEmail(const int itemId)
{
const QString fileName = getFileFromItemId(itemId);
// Logic in program checks existence of file somewhere else
// and this slot should be called only in case it exists.
Q_ASSERT(QFileInfo(fileName).exists());
QStringList attachment;
attachment.append(fileName);
QMessage msg;
msg.setType(QMessage::Email);
msg.setSubject("File from our app.");
msg.setBody("File from our app is included in attachement.");
msg.appendAttachments(attachment);
QMessageService msgService;
// User will fill reciver email, can write additional info,
// etc. and finally send.
bool success = msgService.compose(msg);
if(!success) {
// Send info for example via QMessageBox
}
}
but working for attachment - it is important to file to be included in attachment list in new email window.
Laethnes
2011-04-29, 09:10
Oh well, I finally found some solution. When I call QMessageService::compose if attachment was set, body and attachment is missing. But if I save the message (email) first, it will be saved with both body and attachment and QMessage instance will be actualized (contain id now) and when I use QMessageService::show, email with all data will be opened. At this point, I can delete saved mail.
vBulletin® v3.8.8, Copyright ©2000-2025, vBulletin Solutions, Inc.