Solved

System.Net.Mail - Remove hyperlink underline??

Posted on 2008-10-03
20
1,469 Views
Last Modified: 2013-12-17
Hi,

I am composing an email and would like to remove the hyperlink underline all together and to only display this as text only.

As soon as I use http:// it underlines the text (in code behind)

Any idea how to stop this in happening???

Regards,

introlux

Using: c#, asp.net
0
Comment
Question by:introlux
  • 7
  • 7
  • 5
  • +1
20 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22635501
do this with the styles...cssClass = "SomeClass"

.SomeClass
{
     text-decoration = "none"
}
0
 
LVL 21

Expert Comment

by:silemone
ID: 22635541
I see the problem...

0
 

Author Comment

by:introlux
ID: 22635640
This is from code behind, so it will not make a difference
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 23

Expert Comment

by:Saqib Khan
ID: 22636242
how about you try without "http" and just "www".

And also why is it you want to disable hyperlink from email? have you tried HTML format?
0
 
LVL 21

Expert Comment

by:silemone
ID: 22636523
well here's how you do it...use a literal control....


so instead of passing directly....pass literalControlName.Text
0
 
LVL 21

Expert Comment

by:silemone
ID: 22636532
so wherever you're placing http://

put the literalControlName.Text instead...
0
 
LVL 21

Expert Comment

by:silemone
ID: 22636603
you could even place literal control on page and just set it's content or build it in code behind.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22636775
The easiest way to do is to use "text" for your email body format:
MailMessage objMail = new MailMessage();
objMail.IsBodyHtml = false;
Email in plain text will not display HyperLink as a clickable link, so there is no "underline".
0
 

Author Comment

by:introlux
ID: 22648144
I have tried to use IsBodyHtml = false and does not make any differ.

I have been looking into literal control method but I have been having few problems. All the examples I have seen it work is at front code, not code behind. Can you please give me an example how I could use this method to see if it works.

Regards,

introlux
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22650352
One approach you can take is to create an HTML format email with <html>, <head>, and <body> tags. In the <head> section, embed your style to remove the underline of the hyperlink in the email body.

protected void Button1_Click(object sender, EventArgs e)
{
	MailMessage mm = new MailMessage();
	StringBuilder sb = new StringBuilder();
	sb.Append("<html><head>");
	sb.Append(Environment.NewLine);
	sb.Append("<style>");
	sb.Append(Environment.NewLine);
	sb.Append("a");
	sb.Append(Environment.NewLine);
	sb.Append("{");
	sb.Append(Environment.NewLine);
	sb.Append("text-decoration:none;");
	sb.Append("}");
	sb.Append(Environment.NewLine);
	sb.Append("</style>");
	sb.Append("</head>");
	sb.Append("<body");
	sb.Append("<br><br>");
	//Replace the following line with your email content
	sb.Append("<a href='http://www.microsoft.com'>http://www.microsoft.com</a>");
	sb.Append("<br><br>");
	sb.Append("</body>");
	sb.Append("</html>");
 
	mm.Body = sb.ToString();
	mm.Subject = "Test email";
	mm.To.Add("toAddress@mydomain.com");
	mm.From = new MailAddress("fromAddress@mydomain.com", "FirstName LastName");
	mm.IsBodyHtml = true;
 
	SmtpClient sc = new SmtpClient("MySmtpServerAddress");
	sc.Send(mm);
 
}

Open in new window

0
 

Author Comment

by:introlux
ID: 22650592
I have tried to do the above, but I dont even recieve an email now. The whole thing compiles but no email is sent.

Regards,

introlux
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22650679
It seems to be related to your SMTP settings. On what machine you can't receive emails? Your local machine or your production server?
0
 

Author Comment

by:introlux
ID: 22651068
Well I have outlook (connected to an exchange server) - I have been recieving email without a problem, also I have been recieving e-mail via old method.

Any idea??
0
 

Author Comment

by:introlux
ID: 22651154
It is working! It was throwing the email to junk for some strange reason!

How will I remove the links then? So the hyperlink does not work??

Regards,

introlux
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22651174
I missed a ">" on line 18...not sure if it was the problem.
Anyway, it works on my machine. Have you checked your Junk folder?
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22651246
Are you saying that you don't want the link to be clickable at all?
0
 

Author Comment

by:introlux
ID: 22651323
yes, do not want the link to have a hyperlink. The user will have to copy and paste the link into the web browser if anything :-)

Also do you know how to add images to the email??
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 22653866
Well, you can't really do that. However, with CSS and a small trick, you can make the link un-clicable.
First, you have to use HTML as your mail format.
Secondly, add this two lines in your <style>
color: #000000;
cursor: text;
Thirdly, when contruct the hyperlink, set href=''. So somethin like:
<a href=''>http://www.microsoft.com</a>
It is technically still a clickable hyperlink, but since href='', no browser will be opened when clicked. Besides, the color of the link is black, so it looks like a plain text string.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22653949
As far as send email with iamges, there are many tutorials available on-line. I did a quick search and found this one:
http://aspalliance.com/1354_Sending_HTML_Mail_with_Embedded_Image_in_NET.all 
0
 

Author Closing Comment

by:introlux
ID: 31506249
Thank you for all the help!
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC - Views 3 40
ModalPopup  question 22 38
Connect Gridview column to Textbox in C# 2 39
Set arraylist as datatable 2 7
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question