Reply
Thread Tools
Posts: 26 | Thanked: 1 time | Joined on Oct 2010
#1
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=T est"));" 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...

Last edited by Laethnes; 2011-04-29 at 09:11.
 
Mike Fila's Avatar
Posts: 412 | Thanked: 480 times | Joined on Feb 2011 @ Bronx, NY
#2
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
 
Posts: 26 | Thanked: 1 time | Joined on Oct 2010
#3
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:

Code:
#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

Code:
#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.

Last edited by Laethnes; 2011-04-27 at 08:22.
 

The Following User Says Thank You to Laethnes For This Useful Post:
Posts: 26 | Thanked: 1 time | Joined on Oct 2010
#4
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.
 
Reply


 
Forum Jump


All times are GMT. The time now is 07:06.