ShowURL "mail to:" Question

Hey gang,

I want to have the user enter information in my app and then click an button and generate an e-mail in their e-mail client to send to me. So I’m trying to format an e-mail using a URL and then the ShowURL command. Is this the best way to do this? Here’s my code:

  Dim MailURL as string = "<a href=""mailto:registration@justaddsoftware.net?"+ _
  "subject=InstallerPro3%20Registration%20Request%20For%20"+NameString.Text+"%20@%20"+EmailString.Text+ _
  "&amp;body="+NameString.Text+"%20with%20e-mail%20address%20"+self.EmailString.Text+"%20"+ _
  "has%20requested%20a%20license%20key%20for%20InstallerPro%203.%0A%0A"+ _
  "Here%20is%20the%20registration%20information%3A%20%0A%0A"+ _
  "Name%3A%20%20"+self.NameString.Text+"%0A"+ _
  "E-Mail%3A%20%20"+self.EmailString.Text+"%20%20%0A%0A%20%20"">Send mail</a>"
  
  ShowURL(MailURL)

I have tested the MailURL string at http://www.rapidtables.com/web/html/mailto.htm and it works. But it doesn’t work in Xojo. Nothing happens.

If I I take out the HTML Tag information and make the string like this:

Dim MailURL as string = "mailto:registration@justaddsoftware.net?"+ _
  "subject=InstallerPro3%20Registration%20Request%20For%20"+NameString.Text+"%20@%20"+EmailString.Text+ _
  "&amp;body="+NameString.Text+"%20with%20e-mail%20address%20"+self.EmailString.Text+"%20"+ _
  "has%20requested%20a%20license%20key%20for%20InstallerPro%203.%0A%0A"+ _
  "Here%20is%20the%20registration%20information%3A%20%0A%0A"+ _
  "Name%3A%20%20"+self.NameString.Text+"%0A"+ _
  "E-Mail%3A%20%20"+self.EmailString.Text+"%20%20%0A%0A%20%20"

Then Xojo does open the email client but the body never gets entered properly. Everything is on the subject line.

So what am I doing wrong? And is show URL the best way to do this? I had been generating an e-mail and using one of my own accounts to send the e-mail behind the scenes directly to me but that doesn’t always work correctly as firewalls and all can have issues with doing it that way.

Thanks,

Jon

In your first example you are not building a URL you are building a snippet of HTML. That is why it would work in a browser.

The second example you are building the link but HTML encoding the ampersands. Don’t do this and you should be fine.

[quote=172334:@Bob Coleman]In your first example you are not building a URL you are building a snippet of HTML. That is why it would work in a browser.

The second example you are building the link but HTML encoding the ampersands. Don’t do this and you should be fine.[/quote]

So don’t use any of the % values? Just use normal text?

I got it. You have to have the & symbol before the word “body.” And it was encoded before.

And no, you don’t need all the % characters in the URL string. Looks like it does all that for you… That’s nice…

I took the liberty of rewriting your routine to how I would have written it:

[code]Dim sSubject As String = "InstallerPro3 Registration Request For " + NameString.Text + " " + EmailString.Text
Dim sBody As String = self.NameString.Text + " with e-mail address " + self.EmailString.Text _

  • " has requested a license key for InstallerPro 3." + EndOfLine + EndOfLine _
  • "Here is the registration information: " + EndOfLine + EndOfLine _
  • "Name: " + self.NameString.Text + EndOfLine _
  • "E-Mail: " + self.EmailString.Text + EndOfLine + EndOfLine

// You just want to URL encode the data only.
Dim sMailLink As String = “mailto:registration@justaddsoftware.net” + _
“?subject=” + EncodeURLComponent(sSubject) + _
“&body=” + EncodeURLComponent(sBody)

ShowURL(sMailLink)[/code]
The biggest change is that you should URL encode the data portions of the link because you don’t know what someone will enter.

OK. There’s not much that the user enters other than their name and e-amil. But it’s a good plan nonetheless…

Thanks. I was not aware of the EncodeURLComponent method.