Stop Auto-hyperlink in Outlook, Gmail etc - c#

My web application sends emails to users. The email contains a link for further user action. Our security standards require that the link in the email cannot be clickable. However, the email clients recognize https:// in the email and auto-link the URL.
Any idea on how to stop the email clients to auto-link. I am thinking if I skip the https://, it may stop the auto-linking. But, if I have to keep the https:// is there any way to avoid auto-linking.
The link in the email is dynamically constructed in the c# code.

I know this thread is old, but I just had this issue myself, and wasn't thrilled by the gif image fix. If you're working with HTML emails, a slightly nicer solution is to break up the link text with a non-rendering tag that tricks the parser. I'm a fan of a simple non-existant <z>:
https<z>://securesite.</z>com
It even works in Stack Overflow posts: https://securesite.com.
Hope this helps someone.

I too wish to disable this, as I believe this is a "valid" use as to not wanting auto-linking (one reason is the designer wants it that way, and they are currently paying the bills).
In email sent that has no images, the header has the domain name in it:
EXTRANET.EXAMPLE.COM
I even put inline styles to make sure it stays white on a black background:
<span style="font-size: 1.5em;padding: 0.5em 0;text-transform: uppercase; font-weight:bold;color:#FFFFFF;text-decoration:none;">EXTRANET.EXAMPLE.COM</span>
Gmail makes this a link, adds an underline and also turns it bright blue instead of the intended white.
At first I tried replacing the dots with . which made it look fine, but didn't fool the Gmail parser.
So, I added a spanned space which work just fine (i.e. it fools Gmail's parser):
<span style="font-size: 1.5em;padding: 0.5em 0;text-transform: uppercase; font-weight:bold;color:#FFFFFF;text-decoration:none;">EXTRANET<span style="font-size:0.1em"> </span>.<span style="font-size:0.1em"> </span>EXAMPLE<span style="font-size:0.1em"> </span>.<span style="font-size:0.1em"> </span>COM</span>

Just create a plain <span> tag around the colon (<span>:</span>) or something like that :)

Replace the actual text with a small GIF image that looks like text.
Email parsers will not recognize text within an image.

My application has a similar security requirement. The solution we used was to add an underscore to the beginning of the URL (_http://).

Sorry to dredge up an old question, but I just tried the answer suggested by pieman72, and found that it didn't work within Outlooks 2007–2013. However, wrapping the individual elements of the URL within table cells did fool the Outlook parser:
Visit <table><tr><td>www.</td><td>website</td><td>.com</td></tr></table> for more information.
I ran a sample message through the Email On Acid test suite and found that it eluded the parser on all the major e-mail clients which automatically convert URLs (Outlook, iOS, Android 2.2, etc.) I did not run any deliverability tests.

#raugfer suggests in another answer: wrap the email/URL with an anchor.
<a name="myname">test#email.com</a>
Quoting from that answer:
Since the text is already wrapped in a hyperlink, Gmail gives up and
leave it alone. :)
(Note: also worked for Apple mail client.)

Necroing the question, I know, but it's relevant... I'd like to present a reasonable scenario where Gmail's auto-linking (at least - haven't tested other clients) doesn't make sense.
A client has an application form on their site, where visitors fill out some personal information and submit it. The system then sends a notification email to the client, presenting the information the visitor supplied.
I'm wanting to enhance the email sent to the client by adding a <textarea> at the bottom, with the fields the visitor filled out presented in CSV format so that the client can simply copy it all and paste it into a spreadsheet.
Gmail, however, fails to recognize that the URLs and email addresses are inside a <textarea> tag, and "helpfully" adds the ... link code around the URL/email - inside the <textarea>. This results in the raw HTML link code showing up in the <textarea>.

This is what i did:
Replace all instances of "." with <span style=""color:transparent; font-size:0px;"">[{</span>.<span style=""color:transparent; font-size:0px;"">}]</span>
Replace all instances of "#" with <span style=""color:transparent; font-size:0px;"">[{</span>#<span style=""color:transparent; font-size:0px;"">}]</span>
These characters stopped it parsing links and email addresses, but aren't visible to the user. The negative is that when you copy and paste an email for example, you end up with: "test1{[{.}]}domain{[{.}]}com"
.

Related

Send RTF in a HTML body by email C#

We have an C# application which sends emails to clients. In these emails can be information about several things and this information can contains a note.
Example email:
Person: John
Age: 35
Note: He works as developer.
(Jonn's picture)
(Excel table)
Person: Mary
Age: 40
Note: (Another picture)
bla bla bla
Until now, we extracted the plain text of the note, but now we want to send the whole note (it is written in rtf format and it can contain images, excel tables and so on).
The email body is made in HTML and can contain several notes.
Does someone know what will be the best option to add these notes to the email? Is it that possible? because the body is a HTML document and I have to add several notes... Maybe is it easier as image (try to get an image from the rtf)? or is it better in HTML?
I hope you can help me or guide me.
Thank you in advance.
Regards.
Definitely its possible. I did similar sort of thing. First read RTF contents into a string (say rtfContent) by using InputStreamReader, then pass this string to a method ConvertRtf2Html(rtfContent). You can follow this link to download the project which converts RTF content to HTML and much(I don't know all the functionality, as I used only ConvertRtf2Html() method)

Mailto does not invoke outlook in chrome.

In view I rendered two links that have mailto. Both of them have body attributes passed to mailto. One has short body text, other very long. When I click on link that has shorter body, it works and outlook opens. Link with longer body does not work (I clicked and nothing happens). But that happens only in chrome. In other browsers both links work. I noticed that in Chrome page source longer body text is made shorter with some notation. This might be the issue.
Does anyone know how to solve this problem? Any help would be appreciated.
Checking for spaces (and removing them) between the colon and the recipients, and between multiple recipients.
Variables that can be used with mailto:
mailto: set the recipient, or recipients, separate with comma
&cc= set the CC recipient(s)
&bcc= set the BCC recipient(s)
&subject= set the email subject, URL encode for longer sentences, so replace spaces with %20, etc.
&body= set the body of the message, including line breaks. Line breaks should be converted to %0A.
A MailTo Generator can be found here.

Hide the src string of an image tag

For example I have:
<img src="http://gateway.com/Providername/NameOfTheSupplier/RequestedImg.jpg" />
Now some customers are complaining that there customers can see the company name in the url. Because its to much work to change the structure of the gateway I use, I search for another way to do it.
Is there a way I can hide the src for the client? For example with base64, or another encryption that can decrypt client-side?
Simple answer: no.
Long answer: no.
Technical answer: Everything that is displayed by a browser needs to be translated to human readable* text in one way. You can obfuscate server side though.
*) human readable also includes very short names like http://gateway.com/P/N/R.jpg.
You can use data URIs, but this requires you to download the image, convert to base64 and embed in the page (or CSS).
This increases the payload by about 34%.
An alternative is to use CSS to style the page, embedding the image URLs in the CSS. This tends to not be dynamic (though it can be) and still, anyone who knows a bit about web technologies can still view the CSS and see the URLs. Using images in this way is of course also not semantic and can break your page in unexpected ways, meaning you will need to expand more efforts on making things that should "just work", work.
You can convert your entire image in base64 code.
For this can use a tons of services available out there.
Just an example:
Convert any image into a base64 string
<a href="data:text/html;charset=utf-8;base64,PCFET0NUWVBFIEhUTUw%2BDQo8aHRtbCBs
YW5nPSJlbiI%2BDQogPGhlYWQ%2BDQogIDx0aXRsZT5QcmV0dHkgR2xvd2luZyBMaW5lczwvd
Gl0bGU%2BDQogPC9oZWFkPg0KIDxib2R5Pg0KPGNhbnZhcyB3aWR0aD0iODAwIiBoZWlnaHQ
9IjQ1MCI%2BPC9jY..."</a>
You can try this piece of code
$('img').filter(function(index){return $(this).attr('src')==='';}).hide();
Can you use Handler for this. This way you can hide URL and if you want you can send image using base64 also with this or just write byte stream in response.
I think this should work and you can also control image path by just changing one piece of code.
Check this link:
http://www.codeproject.com/Articles/34084/Generic-Image-Handler-Using-IHttpHandler
Thanks.

building a multiple email regular expression for a regular expression validator on asp.net c#?

I'm trying to make a form on asp.net where you can send emails. I want to have a textbox where I can type all email addresses which I want to send a message...
However I want to add a validator there so the user always has the correct syntax and therefor, use that string on c# and send the message properly.
For now, I have a validator for a single email address...
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server"
ControlToValidate="tbxAlClEmail" ErrorMessage="E-mail Invalido"
Font-Bold="True" ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="vgpNuevoCliente">
</asp:RegularExpressionValidator>
so, we can see that....
email = \w+([-+.']\w+)#\w+([-.]\w+).\w+([-.]\w+)*
(I know that it is difficult to find an expression regular that can validate all kind of email addresses... but this will have to do)
now I want to addapt this regular expression to an asp.net validator:
email ( (,|;) [SPACE]* email )*
example of results i want:
john#hotmail.com, amy#yahoo.com,diana#hotmail.com; alicia#gmail.com
I hope you can help me with that...
Thanks in advance
What you have won't work to validate email addresses.
Using regex for email validation is extremely hard to do right and there are literally hundreds of examples on the net of validators that get close... but still aren't perfect.
But that's only a small part of the problem anyway. Your absolute best bet is to drop trying to validate the address and simply send the messages while telling the user which addresses failed.
If you are doing it right, then you aren't including every address in the TO field anyway and instead are sending distinct messages to each individual address. Which would make it fairly easy to report errors.
Of course, even then numerous mail servers are configured to not even respond if a bad email address is sent to it and instead they just black hole the message. No amount of validation etc is going to get past that.
For fun, you might want to read the following in its entirety so that you understand the full problem: http://www.regular-expressions.info/email.html

asp.net textareafor - keep newlines

I have an input form used for a forum, where users can post messages.
I capture the comment content text using Html.TextAreaFor.
However, when the user creates newlines in the text (by pressing Enter), those newlines aren't "retained" when I redisplay the new message in the forum.
Is the only solution to replace \n with </br> on the server when processing the message (and if so - how do I go about doing that in the best way?), or is there an automated way of achieving it straight away?
Thank you!
You can do it in two places, either when you accept the data from the user or when you display it. I'd recommend when you get it from them since it will only have to do it once. Either way, you can replace it like this:
myHtml = myHtml.Replace("\n","<br />");
It's as easy as that.

Categories

Resources