An array contains an email. This e-mail looks at the moment like:
testmail%40mail.de
I'm searching for an methode to get this e-mail to readable format for humans. I know everybody would be able to identify '%40' after some time, but I would need to get for example in this case 'testmail#mail.de'
I found the solution to use "System.Net.WebUtility.HtmlDecode()". I use .Net4.0 but there was no readable output using the methode above (output was the same one). I hope to get an easy way to solve this.
The email address is URL encoded therefore you are required to URL decode it.
.NET has the following utilities available for you to do this:
HttpServerUtility.UrlDecode(string) or HttpUtility.UrlDecode(string)
Related
This is an odd (to me anyway) query string problem.
I'm using a installation tool that has web serial number validation. Basically the install passes a users email and serial number to a web page (or a controller method for MVC) and that takes the query string arguments and does magic to validate the installation.
One of the arguments is the email address passed in the query string.
I recently has a user who used ‘+’ email addressing to purchase a subscription. All worked well until he went to install the product and had to get past the validation screen.
After doing some digging I found that instead of receiving
‘joe+foo#gmail.com’
The validation code receives
‘joe foo#gmail.com’
Of course the space ruins the validation attempt as his email address is now wrong.
I've spoken with the install tool company (Advanced Installer, best install tool on the planet) and they claim (and I believe them) that the email is sent correctly.
So that leaves me at how do I get the asp.net mvc querystring parser do to the right thing for that particular argument and pass the string with the '+' to the contoller method ?
It's asp.net mvc 5 if it matters.
Thanks for any help you can spare.
UPDATE
The problem is with the sending, not the reception. the plus sign ends up unencoded so it translate to a space= when it get handled by the query string parser.
So what I am looking for is a way to customize the query string parser for that particular URL (and only that URL).
The shortcut to a fix is to replace spaces with a plus sign in the email arg. Simple, but I hate that kind of hackery in my code I;d prefer to have it use a customized parser to that if I need it else where I can just plug it in any way it goes.
You can customize just about everything else in asp.net mvc so I was wondering if there was a way to do the query string pasring in some custom fashion.
Assuming you are calling the URL from javascript, instead of doing this:
url += "?email=" + email;
Encode the value like this:
url += "?email=" + encodeURIComponent(email);
If you are calling the URL from the server, then:
string encodedEmail = Server.UrlEncode(email);
UPDATE
If you can't change where the URL is getting called, then you don't have any other option than:
HttpUtility.UrlEncode(Request.QueryString["email"]);
or:
email = email.Replace(' ', '+');
It looks like I'm going to have to go with my hack solution of swapping space for a plus sign in that particular query string parameter. Not the ideal solution in my way of thinking, but it will do the trick.
I need to validate user input for an href on the server side and need to make sure only http:// and https:// are allowed as a protocol (if specified at all.) The objective is to eliminate possible malicious code like javascript:... or anything alike.
What makes it difficult is the number of ways the colon could be encoded in such string e.g. :, :, :, : , :. I'd like to transform the value and see it as the browsers do before they render the page.
One option could be building a DOM document using AngleSharp as it does the perfect job when parsing attributes. Then I could retrieve the value and validate it but it seems somewhat of an overkill to build the whole DOM tree just to parse one value. Is there a way to use AngleSharp to parse just an attribute value? Or is there a lib which I could use just for this task?
I also found this question, but the method used in there does not really parse the URIs the way browsers do.
You want the HtmlDecode() method. You may need to add a reference to the project to use it.
how can we check that a validated Email exist Or Not Without Sending test Email by c# codes?
we can check Validation of that email by many ways...
but what about existence?
is it possible to do that or not ?
thanks in advance
You should look at these websites. I've used a similar method to these three in the past when validating users emails for a federal website that required an authentic email address.
http://tools.email-checker.com/
http://verify-email.org/
http://www.technixupdate.com/check-whether-an-email-id-is-valid-or-not/
A mail server will usually quickly send back a response telling you if the email is valid or not, that is what you're going to be looking for.
As well, SO already has a few posts on this:
Checking if an email address exists
is one of them.
Update:
I love the existence tag...!
You could possibly use C# to run a cmd command - telnet. Then output the results to a text file and read them into to your C# app. This should help - http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email You will need to know the details for the mail server names though. You might be able to do this directly from C# but I have only done it through telnet.
I don't know if there's a good way to do what you're looking for, but a solution that might get you part of the way there is to ping the domain to at least make sure that exists.
Here's an MSDN link which explains how to ping from .NET:
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx
You can use a Regex Validation on the form before the user submits the data. It's an inbuilt tool in Microsoft Visual Studio where you can pretty much drag and drop :)
You should be able to find it in the validation section . Regular expression Validator
A product that we use is storing the Letter Express (Mail Merge) template as a BLOB (or CLOB...I cannot remember right now). We use the Product's API to call this letter express and send an email.
Now, we want the content of the email to be captured and stored in a separate field. The API provides us with a LetterExpress.WordDocument property which has the template. This is however a byte[].
I am trying to get this into a string object so that I can populate the place holders and then store it in a different field.
This is the code that I was trying.
System.Text.Encoding.ASCII.GetString(LetterExpress.WordDocument)
However, I get an error as follows
The best overloaded method match for
'System.Text.Encoding.GetString(byte[])'
has some invalid arguments
Why am I getting this error?
How can I ascertain what is the encoding that is being used for the LetterExpress.WordDocument? Or is there a generic method that can convert it into a string?
You're getting that error because the LetterExpress.WordDocument property you think is a byte[] really isn't one. Verify that the type of that property really is what you think it is.
It sounds like this is an actual .doc file, and a .doc file is much more complicated than just a string encoding. If you want to extract the text from a word document, you need something like the Aspose Tools. The ability to do this is not built into the framework. There is not System.Text.Encoding you can use, and no generic method including with .Net that can do this.
Hope someone may be able to help. What i am looking to do is create a small winform app in c# to read the content of a email from a pop account, and upload key values to a sql automatically. The email format is always the same for each email, eg,
First name :
Last name :
Phone number :
etc...
Currently the emails are being stored in a pop 3 account however i want a way to reduce having to key the information into the sql by hand.
Can anyone advise how i would go about doing this or could recommend some guides?
Thanks.
Steve
I would recommend using a class like this POP3 client at CodeProject to read the mail messages.
Once you have the message content, you should be able to fairly easily parse the string, since you know the exact format. There isn't enough information to recommend the best option for this - it depends on whether it's fixed format, delimited, separate lines, etc, but using regular expressions or even String.Split should make this fairly simple.
We use a purchased tool Email2Db tool to process incoming email. It is inexpensive and easy to configure. I wrote custom vb scripts for our needs but a simple insert into a db would not require any coding.