Results 1 to 10 of 10

Thread: attaching file after opening default email client(Qt 4.4,Linux)

  1. #1
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Post attaching file after opening default email client(Qt 4.4,Linux)

    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--
    Qt Code:
    1. QDesktopServices::openUrl(QUrl("mailto:?subject=&body=&attach="));
    To copy to clipboard, switch view to plain text mode 
    now if i give the path of the picture--
    Qt Code:
    1. QDesktopServices::openUrl(QUrl("mailto:?subject=&body=&attach=/path/Desktop/buttons/button1.PNG"));
    To copy to clipboard, switch view to plain text mode 
    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' - -
    Qt Code:
    1. fileName = QFileDialog::getOpenFileName(this,tr("Open File"), QDir::currentPath());
    To copy to clipboard, switch view to plain text mode 

    but, if i write --
    Qt Code:
    1. QDesktopServices::openUrl(QUrl("mailto:?subject=&body=&attach=fileName"));
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by rishiraj; 28th January 2009 at 07:27. Reason: spelling error
    If everything seems to be going well, you have obviously overlooked something.

  2. #2
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: attaching file after opening default email client(Qt 4.4,Linux)

    have you tested something like this ?

    Qt Code:
    1. QDesktopServices::openUrl(QUrl("mailto:?subject=&body=&attach=" + filename));
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to jpujolf for this useful post:

    rishiraj (28th January 2009)

  4. #3
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: attaching file after opening default email client(Qt 4.4,Linux)

    Hi,
    thanks a lot,your suggestion worked.
    If everything seems to be going well, you have obviously overlooked something.

  5. #4
    Join Date
    Nov 2007
    Posts
    15
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: attaching file after opening default email client(Qt 4.4,Linux)

    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:penUrl(QUrl("mailto:test@test.com?subject=test&bod y="+l_string+"&attach=" + l_string));

    Thanks in advance.

  6. #5
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: attaching file after opening default email client(Qt 4.4,Linux)

    yes, it is not working on windows for me too.
    Any suggestions?

  7. #6
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: attaching file after opening default email client(Qt 4.4,Linux)

    Have you checked that l_string contains no spaces ? Not tested, but you could try this :

    Qt Code:
    1. QDesktopServices:openUrl(QUrl("mailto:test@test.com?subject=test&body="+l_string+"&attach=\"" + l_string + "\""));
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to jpujolf for this useful post:

    avipachar (23rd February 2012)

  9. #7
    Join Date
    Nov 2011
    Posts
    9
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: attaching file after opening default email client(Qt 4.4,Linux)

    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:penUrl(QUrl("mailto:test@test.com?subject=test&bod y=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

  10. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: attaching file after opening default email client(Qt 4.4,Linux)

    On the Linux machine it was working by accident and not design.

    The file is not attached because the mailto URL scheme does not specify "attach" as a special header like "body". You may specify any header defined in RFC 822, 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.
    Last edited by ChrisW67; 24th February 2012 at 06:52.

  11. The following user says thank you to ChrisW67 for this useful post:

    avipachar (24th February 2012)

  12. #9
    Join Date
    Aug 2012
    Posts
    4
    Qt products
    Platforms
    Windows

    Default Re: attaching file after opening default email client(Qt 4.4,Linux)

    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.

  13. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: attaching file after opening default email client(Qt 4.4,Linux)

    As explained above, you cannot reliably use mailto: links. You can try any of the Windows-specific methods;
    1. Simple Mapi (does not support HTML tags in the body)
    2. Extended Mapi (Does support HTML tags)
    3. CMC (Common Messaging Calls) Is a non-platform specific. When it is used on Windows it will access the MAPI properties.
    4. MAPI Activex
    5. CDO (Collaboration Data Objects).
    6. Automating Outlook
    7. and probably others

    I would guess that CDO is worth the most investigation.

Similar Threads

  1. Replies: 7
    Last Post: 5th January 2009, 08:27
  2. Opening swf file in the default browser
    By munna in forum Qt Programming
    Replies: 16
    Last Post: 5th May 2006, 09:33
  3. Opening the default mail client
    By munna in forum Newbie
    Replies: 5
    Last Post: 3rd April 2006, 13:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.