Simple "MAILTO:" with Attachment

I wish to fire the users default mail client, and start a email compose, supplying a file to be attached.

Do not wish to fill in the email address to send it to, don’t want to actually sent it…
I want the user to fill in that data and press send.

Can this be done with SHOWURL(“mailto:”)
if not I can work out AppleScript for OSX… but need a Windows solution as well

I never found a way to do it using mailto (it’s been a few years since I’ve looked, though). AFAIK, the only built-in Xojo solution for email attachments is to use an SMTP Socket.

I do not have a solution for Windows at hand, but on OSX I used either one of these:

With MBS plugins:

Dim fAtt As FolderItem = im.imGetDataFolderItem.Child(fName) Call NSWorkspaceMBS.openFile(fAtt,"Mail",True)

Or with AppleScript:

on run {theSubject, theBody, theAttachment} -- set theFile to POSIX file theAttachment tell application "Mail" set newMessage to make new outgoing message with properties {visible:true, subject:theSubject, content:theBody & return & return} tell content of newMessage make new attachment with properties {file name:theFile} at after the last paragraph end tell activate end tell end run

After dragging the AppleScript ‘OSXSendMail’ into the app, I call it like this:

OSXSendMail(theSubject, theBody, theAttachment)

… and Mailto does not work with attachments, in most environments:

[code] Dim s1 As String = “mailto:” + email + ", " _
+ “notwo@snai1mai1.com” _
+ “?subject=” + email_subject _
+ “&cc=buddys@snai1mai1.com” _
+ “&bcc=secretfriend@snai1mai1.com” _
+ “&body=” + message_text

REALbasic.ShowURL(s1)  // works

Dim fPath As String = SpecialFolder.Documents.Child(fName).URLPath
Dim s2 As String = "mailto:joe@sixpack.com " _
+ "?subject=Backup of database " + dbFileNam _
+ "&attachment=" + fPath

REALbasic.ShowURL(s2)  // works rather not

[/code]

Take out the “file:” and the first slash and Oliver’s second example works in OSX.

Dim fPath As String = SpecialFolder.Documents.Child(fName).URLPath
fPath = fPath.Right(fPath.len - 6) 'You need a path like /localhost/directory/file.txt
Dim s2 As String = "mailto:joe@sixpack.com " _
+ "?subject=Backup of database " + dbFileNam _
+ "&attachment=" + fPath
    
REALbasic.ShowURL(s2)  // works for me using the built in mail client

Don’t know about Windows though.

well I tried it… and it does not work… no attachment or evidence of an attempt even

  Dim fPath As String = SpecialFolder.Desktop.Child("mask.png").URLPath
  msgbox str(SpecialFolder.Desktop.Child("mask.png").exists)
  Dim s2 As String = "mailto:you@home.com " _
  + "?subject=test " _
  + "&attachment=" + fPath
  
  REALbasic.ShowURL(s2)  // works rather not
  msgbox "done"

and first msgbox does say TRUE

URLPath will have the wrong format, according to what Bill said. Try ShellPath or NativePath.

Or use the fix that Bill did.

fPath = fPath.Right(fPath.len - 6) 'You need a path like /localhost/directory/file.txt

no combination of pathtype works

Interesting, it works with gif files (what I tested, but it attaches them inline). But I just tried with a zip and it doesn’t work. I also had to take the space out after the email address, by the way.

Well dangit, I can’t get my original gif file to attach itself now either. What the heck did I do?

[edit: This is driving me bonkers. I tested it before, it worked. I didn’t save the project, now I’m trying to test it and it isn’t working. ARRRRGGGGGHHHHH!!!]

At this point, the only thing I can think of is that I’d manually attached the file once and not closed it, then tried my fix and thought that was a positive result. I can’t get it to work no matter what I do at this point. sad panda

[quote=83661:@Dave S]I wish to fire the users default mail client, and start a email compose, supplying a file to be attached.

Do not wish to fill in the email address to send it to, don’t want to actually sent it…
I want the user to fill in that data and press send.

Can this be done with SHOWURL(“mailto:”)
if not I can work out AppleScript for OSX… but need a Windows solution as well[/quote]
Pretty sure the MAILTO uri doesn’t support such a thing - http://tools.ietf.org/html/rfc6068

ok… the answer is No…

Suggestion: we used to mess about with SMTP settings in our apps - with user’s having to set all their settings correctly (they never know what they are, then the password changes etc), so moved on to an smtp service that offers an API (JangoMail is the one we selected, but there are plenty of others).

This means we can use a securesocket to communicate with the JangoMail server and send email messages from our apps. You just set the message up, display a dialog for the user to complete any missing data (e.g. the recipient) and send as a SOAP or POST message to the provider using their API.

We found though that JangoMail doesn’t get on that well with hotmail, live and outlook accounts (sender limits from their servers) so we ended up going a step further and created a web-service that accepts the message (simple with web-edition), which passes it on to JangoMail. Periodically it checks the message logs for any errors reported and re-send via another email channel (using SMTP to one of our alternate email accounts). An alternative, to JangoMail is to set up your own email server to relay messages from the web-service…but logging and the API they provide is far more work than I’m prepared to do for email.

Hope that helps.

MailChimp (Mandrill), SendGrid etc provide this functionality out of the box. I give the users of my application the possibility to write a sentence, then automatically attach some logged information and this is sent to me. See http://www.manual.mothsoftware.com/reference/Troubleshooting/troubleshooting.html for a screenshot.

[quote=83661:@Dave S]I wish to fire the users default mail client, and start a email compose, supplying a file to be attached.

Do not wish to fill in the email address to send it to, don’t want to actually sent it…
I want the user to fill in that data and press send.

Can this be done with SHOWURL(“mailto:”)
if not I can work out AppleScript for OSX… but need a Windows solution as well[/quote]

Dave here is how to have code open the default mail program and pre populate it for OSX. You can do the same with Windows however my issue is that Windows doesn’t have a default Mail Program and I can’t assume the user will be using Outlook 2007 on the Computer since alot of users are using Outlook 365 which is cloud (browser) based. Anyhow this is how I do it easily.

Dim EmailCMD as New Shell
#IF TargetMacOS Then
  EmailCMD.Execute("open ""mailto:support@intelligentvisibility.com?subject=Intelligent Subnet Calculator Support Request&body=""")
  
#ELSEIF TargetWin32 Then
  MsgBox "Email Support Requests" + EndOfLine + EndOfLine +"support@intelligentvisibility.com"
#ENDIF

Sorry Dave I just caught the attachement part late.

I know on Mac you can :

open -a Mail file.txt

and this will auto open and attach. I am trying to incorporate the email info being filled out also now.

This is not for them to mail something to me.
This is for the user to email encrypted data from within the application to other users .

To whom the mail is sent doesn’t really matter. You know users: make something automatic and then it works.

The point is… I am not going to pay for a service like MailChimp… nor am I going to require my users to buy a service…
And in anycase the problem of integrated said service to Xojo still exists…

And I DO NOT want an email address filled in… a subject perhaps, an attachment for sure.
But I wish for the users email client to be used… and for a pre-composed email sans destination to be displayed, where they are required to enter the destination email address and click send, or cancel the whole thing.

But the email to be handled by their current email client…

open -a Mail file.txt

does exactly what I am looking for… Only problem is it ASSUMES that OSX Mail is their email client…which may be acceptable .