Question

I've got a c# process that send emails to customers with a hyperlink in the mail. The mail is send from a SQL Server stored proc. My c# program just invokes the sp. The hyperlink works fine in Outlook, but on online gmail it only shows as text. It is not clickable. My mail text looks something like:

Hi. 
This is the hyperlink:<br>
<a href=\"serveraddress\Documents\\123_128635312685687531322.gif\">
Click Here</a><br><br>

What should I do to fix it?

EDIT: My code:

string email = "xx@gmail.com;
string password = "MyPassword";

var credentials = new NetworkCredential(email, password);
var msg = new MailMessage();
var smtpClient = new SmtpClient("smtp.gmail.com", 587);

msg.From = new MailAddress(email, senderName);
msg.To.Add(new MailAddress(toAddress));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;

smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = credentials;
smtpClient.Send(msg);

EDIT 2: Compile message being send:

string message = @"Hi. <br>
This is the intro line in the mail message.<br>";

using (DataTable dtLinks = data.ExecuteDataSet(@"SELECT * 
                                                    FROM LessonFiles
                                                    WHERE Course = " + dr["Course"].ToString().DBValue() + @" AND 
                                                        Lesson = " + dr["NextLesson"].ToString().DBValue()).Tables[0])
{

int i = 0;
foreach (DataRow drLink in dtLinks.Rows)
{
    i += 1;
    message += "<a href=\"" + drLink["Link"].ToString() + "\">" + drLink["Lesson"].ToString();
    message += i == 1 ? "" : " file " + i;
    message += "</a>" + "<br>";
}
}
message += "<br>Regards<br><br>";
Was it helpful?

Solution 2

Seems like something was funny with the hyperlink itself. Using http://serveraddress/Documents/logoColourBG635315550177822533.jpg seems to work.
The original contained backslashes in the path. The fact that it showed the hyperlink in Outlook led me to believe the address was correct. Thanks for all your help.

OTHER TIPS

try to add target="_blank", like this...

message += "<a href=\"" + drLink["Link"].ToString() + "\"target=\"_blank\">" + drLink["Lesson"].ToString();

creating mail message object...

var smtp = new System.Net.Mail.SmtpClient();
                    smtp.Host = "smtp.gmail.com";
                    smtp.Port = 587;
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.Credentials = new NetworkCredential(UserName, Password);
                    smtp.Timeout = 20000;

                    MailMessage Msg = new MailMessage();
                    Msg.IsBodyHtml = true;
                    MailAddress fromMail = new MailAddress(SenderID);
                    Msg.From = fromMail;
                    Msg.To.Add(new MailAddress(TosendID));
                    Msg.Subject = subject;
                    Msg.Body = body;

In body add ur code.....

Hope This Helps.........

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top