문제

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>";
도움이 되었습니까?

해결책 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.

다른 팁

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.........

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top