Sending variables as body of mailto on asp:button - html

I have a website which I want users to be able to share a link via email. This particular page is the mobile version.
I have an asp:button using mailto and I need to pass variables from the page to build the URL in the email body.
<asp:Button ID="btnEmail" runat="server" Width="70%" Text="Share Property" PostBackUrl='<%#"mailto:?subject=Check out this property at xxx - " & DataBinder.Eval(Container, "DataItem.PropertyName") & "body=" & DataBinder.Eval(Container, "DataItem.PropertyID")%>'/>
The mailto is working and the subject is populating but the mail body seems to contain the viewstate of the page:
__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTM4ODYwNDQ2Mg9kFgJmD2QWAgIDD2QWAmYPZBYCAgEPFgIeC18hSXRlbUNvdW50AgEWAmYPZBYKAgEPFgIeCWlubmVyaHRtbAXCAzx1bCBjbGFzcz0nc2xpZGVzJz48bGk%2BPGltZyBzcmM9Jy4uL2Z0cC9wQlJBTkNIX1AxMzQxLmpwZycgLz48L2xpPjxsaT48aW1nIHNyYz0nLi4vZnRwLzYtQlJBTkNIX1AxMzQxLmpwZycgLz48L2xpPjxsaT48aW1nIHNyYz0nLi4vZnRwLzctQlJBTkNIX1AxMzQxLmpwZycgLz48L2xpPjxsaT48aW1nIHNyYz0nLi4vZnRwLzgtQlJBTkNIX1AxMzQxLmpwZycgLz48L2xpPjxsaT48aW1nIHNyYz0nLi4vZnRwL2FCUkFOQ0hfUDEzNDEuanBnJyAvPjwvbGk%2BPGxpPjxpbWcgc3JjPScuLi9mdHAvYkJSQU5DSF9QMTM0MS5qcGcnIC8%2BPC9saT48bGk%2BPGltZyBzcmM9Jy4uL2Z0cC9jQlJBTkNIX1AxMzQxLmpwZycgLz48L2xpPjxsaT48aW1nIHNyYz0nLi4vZnRwL2RCUkFOQ0hfUDEzNDEuanBnJyAvPjwvbGk%2BPGxpPjxpbWcgc3JjPScuLi9mdHAvZUJSQU5DSF9QMTM0MS5qcGcnIC8%2BPC9saT48L3VsPmQCAg8VBRpSZWR3b29kIENsb3NlLCBTb3V0aCBPeGhleQM2NzUDUENNBVAxMzQxnwFPbmUgYmVkcm9vbSB0b3AgZmxvb3IgZmxhdCB3aXRoIGZpdHRlZCBiYXRocm9vbSwgZml0dGVkIGtpdGNoZW4gd2l0aCB3YXNoaW5nIG1hY2hpbmUsIGZyaWRnZSwgY29va2VyIGFuZCBtaWNyb3dhdmUuICBBdmFpbGFibGUgbm93IGZ1cm5pc2hlZC4gIEVuZXJneSBSYXRpbmcgRS5kAgMPDxYCHgtQb3N0QmFja1VybAUlaHR0cDovL21hcHMuYXBwbGUuY29tL21hcHM%2FcT1XRDE5IDZTRWRkAgUPDxYCHwIFHFJlcXVlc3RWaWV3aW5nLmFzcHg%2FSUQ9UDEzNDFkZAIHDw8WAh8CBWNtYWlsdG86P3N1YmplY3Q9Q2hlY2sgb3V0IHRoaXMgcHJvcGVydHkgYXQgSm9obiBXaGl0ZW1hbiAtIFJlZHdvb2QgQ2xvc2UsIFNvdXRoIE94aGV5Ym9keT10ZXN0UDEzNDFkZGQlH8aveHqM96GJK6rcUKFtYormuw%3D%3D&__PREVIOUSPAGE=jXBhZExXbPAJGCoKEgVxPvQrYIK2wX4xu1Pu8m0He281&__EVENTVALIDATION=%2FwEWBQLLnPHNBQKLm%2B%2BxDQKTlZGGAQKbi8jQCALB16nOAksIgJxExXvoFLdOr%2FT%2F56iiVmxW&ctl00%24MainContent%24myDataRepeater%24ctl00%24btnEmail=Share+Property
Where am I going wrong?

A Button wants to do a postback, which contains all form fields.
You can also use a <a href="mailto:..."> to initiate an e-mail from the user's mail program. You don't need the runat=server here.
You can style that link to look like a button.

Related

Want to create a link I can send people that will open their email app with a pre-written message (NOT A LINK ON MY OWN WEBPAGE OR APP)

I am trying to replicate something someone has done in this link https://l.instagram.com/?u=http%3A%2F%2Ftinyurl.com%2Fyd49a4ow&e=ATMn3WfYRw5VZzFDz9FU9Pp0jqk5uBpX0Vo4n2MffH-mr8W5f84IEmpo-Rbx3neyIU0ehQcntNJuRsSGfW9bjw&s=1.
When on a mobile app the link opens the mail app with a pre-written email body subject and recipients.
It is similar to the mailto function if I were designing my own web page and using HTML but this is a link I want to be able to email and share with people.
Thanks so much for your help!
Checkout mailto links: https://css-tricks.com/snippets/html/mailto-links/
The long-and-short of it is that you can make a link that looks like this:
Email Us
Basically, you are using the link's query parameters to preset the subject line, recipient, and body of the email.
Build your link like so:
mailto:<the *recipient's* email>?subject=<subject line>&body=<email content>
Then you can add the following options:
Carbon Copy (cc) and Blind Carbon Copy (bcc)
Each email must be separated by a comma (&cc=email#example.com, email2#example.com)
Subject (subject)
Email body text (body)
Make sure to URL-encode the subject and email body text as well.

How to send personalized links in a mail?

I'm setting up a solution for a backoffice website where the user should be able to send mail for some technician.
In this mail, the technician must be able to click on a specific button and this will open a new web page with adaptative parameters such as the date, the address, the client name, etc..
To do so, I need to send at least one parameter in the mail (the mission id of this technician) and this parameter must be different in each mail.
I already tried a solution in which the mail is written in HTML and then I could insert a form in the body or a link for a GET request. But it seems that not all the mail server can handle this way of work.
In Gmail it works for everything, but using Safari for Mac OS X, or Outlook messenger it doesn't.
Using POST:
<form action='__the_website_to_post_request__' method='post'>
<input name='id' type='hidden' value='$id'>
<button type='submit' formmethod='post'>Upload reports</button>
</form>
Using GET:
<a href='__the_website_to_post_request__?id=".$id."&tok=".md5($id)."'>
Upload reports
</a>
In Outlook, no button appears and in Safari, the post method doesn't work.
Maybe another solution exist doesn't matter which mail application I should use ?

How to make an email with submit button, which triggers a post request

I want to send an email which has a submit button, on click of which, a post request would be triggered.
How can I create such an email?
What kind of code would be required?
The code I have written:
<h1>Show a push button:</h1>
<p>The button below activates a JavaScript when it is clicked.</p>
<br/>
<input type="button" value="Click me" onclick="msg()">
That approach you appear to be trying to take is to use JavaScript. This absolutely will not work. Email clients do not allow JavaScript to execute in HTML formatted email.
You could place a regular form inside the email:
<form action="http://example.com" method="POST">
<button>Submit</button>
</form>
… however, form support in email clients is not perfect.
The safe approach is to ask the user to do a two-step process: use a regular link to a webpage containing the form which the user can load in their web browser and then click the submit button for.
If you don't care about the usual protections, then you could have JavaScript submit the form on that page automatically, or change the endpoint that expects a POST request to expect a GET request and use a regular link in the original email.

Submit to HttpHandler results in RequestType GET instead of POST

My ActionHandler.ashx file should be POSTed yet upon entry to ProcessRequest the context.Request.RequestType is always "GET".
Background:
This HttpHandler currently works OK (i.e. clicking a link in an email causes my ActionHandler.ashx to be entered and the querystring is processed correctly). For example:
https://mdwdata/CorporateBrain/ActionHandler.ashx?Action=MarkComplete&ID=1024~nzmewoojgnn&CUID=13
is the URL for the link shown as Mark-Complete in the image just below:
But now I am trying to improve it by following this advice in a previous SO thread :
"In the body of the email, instead of sending a link, include an HTML form that contains a button which performs a postback to your server."
Problem Summary: When I click the Submit button, my handler is entered with verb GET not POST (hence, I have no access to the hidden form data in the Request.Form collection.
Here is a snippet (image) of the email body
If I can get the Submit to post the hidden form variables to my handler, then of course I would remove the links. In the debugger, I verified the form data and it looks good me:
I added this line to my web.config file:
<add path="ActionHandler.ashx" verb="GET,POST" type="System.Web.UI.SimpleHandlerFactory" validate="true" />
Also, my email client is Thunderbird.
What would cause the request to be GET instead of POST?
The short answer to this problem is that Thunderbird does not POST to the URL in the Action attribute of the HTML form tag. Even the newest version of Thunderbird (version 31.2.0) "ignores" the POST and requests the URL via GET.
The construction of the HTML form is properly done and other email clients I have tested work fine:
Microsoft Office 365 Outlook Web App
Google GMail
So, I guess I am doing it "right" but some email clients apparently don't support this (even my favorite which is Thunderbird).

How to use codebehind to create email hyperlink in asp.net visual basic?

I've created a hyperlink on a web page, and I'm trying to have it open an email client with a variable email address, so I want to set the email address in the code behind for a hyperlink control. However, when I click the link nothing happens. I'm able to do this for an html link, so I'm not sure what's going wrong. Here is my code:
Email.NavigateUrl = Me.ResolveUrl(String.Concat("mailto:", Results.sstrEmail))
Where Email is the asp:hyperlink control, and results.email is a string containing an email address.
Have you tried not using the Me.Resolveurl method? The final href of the link should just be href="mailto:mail#domain.com" and should not include the website url.
Email.NavigateUrl = String.Concat("mailto:", Results.sstrEmail)