I am implementing an app, which send email to employees in company. That email contains a hyperlink which direct to a pdf file on a shared server folder.
Example url of server folder:
\\server_name\folder_parent\folder_child\file.pdf
In my C# code, I use a string to contain html code like this code below
private static string getHTML(DataTable dt) {
string myBuilder = "";
myBuilder += "<table id='customers' style='font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif; width: 100%; border-collapse: collapse;'";
myBuilder += "<tr>";
foreach (DataColumn myColumn in dt.Columns)
{
myBuilder += "<th style='font-size: 1.1em; border: 1px solid #98bf21; padding: 5px 7px 4px 7px;background-color: #A7C942;'>";
myBuilder += myColumn.ColumnName;
myBuilder += "</th>";
}
myBuilder += "</tr>";
int count = 0;
foreach (DataRow myRow in dt.Rows)
{
myBuilder += "<tr>";
if (count % 2 == 0)
{
foreach (DataColumn myColumn in dt.Columns)
{
myBuilder += "<td style='font-size: 1em; border: 1px solid #98bf21; padding: 3px 7px 2px 7px;'>";
if (myColumn.ColumnName == "Address")
{
myBuilder += "<a href='" + myRow[myColumn.ColumnName].ToString() + "' style='display:block;'>Link!</a>";
}
else
{
myBuilder += myRow[myColumn.ColumnName].ToString();
}
myBuilder += "</td>";
}
}
else
{
foreach (DataColumn myColumn in dt.Columns)
{
myBuilder += "<td style='font-size: 1em; border: 1px solid #98bf21; padding: 3px 7px 2px 7px; color: #000000; background-color: #EAF2D3;'>";
if (myColumn.ColumnName == "Address")
{
myBuilder += "<a href='" + myRow[myColumn.ColumnName].ToString() + "' style='display:block;'>Link!</a>";
}
else
{
myBuilder += myRow[myColumn.ColumnName].ToString();
}
myBuilder += "</td>";
}
}
count++;
myBuilder += "</tr>";
}
myBuilder += "</table>";
return myBuilder;
}
This code gets data from a DataTable and shows it like a table in html code.
This is data for DataTable
dt.Rows.Add("bala", "24", "http://www.google.com", "999444444");
dt.Rows.Add("chendur", "23", "http://www.facebook.com", "9999999999");
dt.Rows.Add("chchandru", "22", @"file:///\\server_name\folderA\folderB\file.pdf", "888888888");
So when I open email on chrome (mail.google.com), the link contains local link didn't work and there was no hyperlink in that text.
I tried with http link like google or facebook and that worked but file link didn't as you can see from this image below.
About the file:///
, I tried to write an html file and that worked.
<td><a href="file:///\\server_name\folderA\folderB\file.pdf">LINK</a></td>
I have read many articles about this and they say "security problems".
The thing is this app only send email between employees in the same company and they use a shared server for using internet and sending email. (All computers in company connect to a same server).
So is there any possible way to send local link like this situation? If it doesn't, is there any possible solution for me to fix this situation? The requirement is just "You click a link in your email and it's automatically open a file on a local link."
p/s: Of course I got this
MailMessage completeMessage = new MailMessage(From, To, Subject, mailBody);
completeMessage.IsBodyHtml = true;