email hyperlink in MailMessage - asp.net

I'm using the following as part of sending a .net 4 email. I'd like to show the reply to text as an email hyperlink but can't quite get the format correct.
nMail.Body = Description " + txtdescription.Text +
"<br />Reply to (click here):" + txtemail.Text);

Wrap the address in an anchor tag <a> to make a link. Also make sure you encode the input.
Use HttpUtility.HtmlEncode on text and Uri.EscapeUriString on links.
nMail.Body = "Description " +
HttpUtility.HtmlEncode(txtdescription.Text) +
"<br />Reply to <a href=\"mailto:" +
Uri.EscapeUriString(txtemail.Text) +
"\">" +
HttpUtility.HtmlEncode(txtemail.Text) +
"</a>");

Use the following if the e-mail address is contained in txtemail.Text. Remember to first validate the content of txtemail.Text. The output of the following is a hyperlink to an e-mail address that also contains the e-mail address as the hyperlink text.
nMail.Body = "Description " + txtdescription.Text + "<br />Reply to (click here): " + "<a href='mailto:" + txtemail.Text + "'>" + txtemail.Text + "</a>");

You can write <a href='mailto:username#example.com'>Link Text</a>.

Try this
private string BuildEmailText(string description, string replyToAddress, string replyToText)
{
return string.Format("{0} <a href='{1}'>{2}</a>", description, replyToAddress, replyToText);
}

Related

Change asp message box header / title

How can I change the title of my message box
Here is my code-behind:
string myStringVariable1 = string.Empty;
myStringVariable1 = "Policy Number:" + " " + txtPolNo.Text.ToString() + " " + "with Issuance office:" + " " + dropIssOff.Text.ToString() + " " + "was not found on the database. Please make sure that your inputs are correct.";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable1 + "');", true);
No, You can't change that title. Alternatively you can use the jQuery alert/dialog box to achieve the same.

embed image to body in html email in asp.net

How shall i write the code to embed image to email body? whats wrong?
mMailMessage.Body += Server.MapPath(#"<img src=""/Styles/Images/logo.png""");
.
You are mapping a path to a file called "<img src=""/Styles/Images/logo.png"""!
What you want to do is something like this:
mMailMessage.Body += "<img src=\"" + Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + #"/Styles/Images/logo.png" + "\"/>";

Posting text with link to facebook wall using C# sdk

I am using facebook api for posting to the facebook wall post.THe post is getting displayed in the wall but i am not able to show the link which redirects to the site when it is clicked.
I need to show both the post as well as the link which points the posted post.
Following is my code
string viewDetailsLink = context.Url.GetLeftPart(UriPartial.Authority).ToString();
viewDetailsLink = viewDetailsLink + "/" + "Blog" + "/Index/" + "0/" + blogPost.Id;
viewDetailsLink = "<a href='" + viewDetailsLink + "'/>" + "click here to open" +"</a>";
But the whole thing is displayed as string instead of click here to open.
How do i resolve this?
You're seeing text instead of a link because you're closing our anchor tag prematurely. Try this instead:
viewDetailsLink = "<a href='" + viewDetailsLink + "'>click here to open</a>";
Here is the issue with your code:
viewDetailsLink = "<a href='" + viewDetailsLink + "'/>" + "click here to open" +"</a>";
Shouldn't close tag here ^ ^ No need to concat ^
Your code, fixed and prettied up a bit:
string viewDetailsLink = context.Url.GetLeftPart(UriPartial.Authority).ToString();
viewDetailsLink = String.Format("{0}/Blog/Index/0/{1}", viewDetailsLink, blogPost.Id);
viewDetailsLink = String.Format("<a href='{0}'>click here to open</a>", viewDetailsLink);

asp.net GridView and Checkboxes Dynamic Bind

I am having a little issue that I don't seem to understand the best way to approach.
I have a GridView that get automatic column generations based on the query I run. The GridView will contain (Name) (Description) (Edit) (Delete) (View) (Admin).
Now because the Edit, Delete, View... are bit's in the database when the query returns the results and binds the data with the GridView I get these grayed out Checkboxes with checked if True or Unchecked if False.
Now because I didn't create those disabled checkboxes are they really a checkbox or are the something that's just display like that... If they are really a checkboxes how do I access them and enable or disable them? I tried looping through each cell in grid but when I say cell.text it gives me empty string back... What would be the best way to approach this or am I misunderstanding the DataBind of a bit fields?
Thanks all for your help.
UPDATED
string sSQLAccess = "SELECT ap.n_Name 'App', a.b_Edit 'Edit', a.b_Delete 'Delete', a.b_View 'View' " + Environment.NewLine
+ "FROM tbl_Actions a " + Environment.NewLine
+ "JOIN tbl_Applications ap ON ap.u_ID = a.u_ApplicationID" + Environment.NewLine
+ "JOIN tbl_Roles r ON r.u_ID = a.u_RoleID" + Environment.NewLine
+ "WHERE a.b_Deleted = 0" + Environment.NewLine
+ "AND ap.b_Deleted = 0 " + Environment.NewLine
+ "AND r.b_Deleted = 0 " + Environment.NewLine
+ "AND a.u_RoleID = '" + Request.QueryString["ID"] + "'" + Environment.NewLine;
grdAccess.DataSource = vwAccess;
grdAccess.DataBind();
The checkbox will not be enabled unless the gridview is in edit mode - you would need to define an edit template for the gridview.

Error while sending mail (attachment file)

in my application i am using to send mail with attachments i write the code like this
Using System.Net.Mail;
MailMessage mail = new MailMessage();
mail.Body = "<html><body><b> Name Of The Job Seeker: " + txtName.Text + "<br><br>" + "The Mail ID:" + txtEmail.Text + "<br><br>" + " The Mobile Number: " + txtmobile.Text + "<br><br>" + "Position For Applied: " + txtPostionAppl.Text + "<br><br>" + "Description " + txtdescript.Text + "<br><br></b></body></html>";
mail.From = new MailAddress ( txtEmail.Text);
mail.To .Add (new MailAddress ( mailid));
mail.Priority = MailPriority.High;
FileUpload1.PostedFile.SaveAs("~/Resume/" + FileUpload1.FileName);
mail.Attachments.Add(filenme);
SmtpMail sm = new SmtpMail();
sm.Send(mail);
it is giving error at attachment like mail.Attachemts.Add(filena)
like this
'System.Collections.ObjectModel.Collection.Add(System.Net.Mail.Attachment)' has some invalid arguments.
Your syntax is wrong. See this article for the correct syntax,
http://www.systemnetmail.com/faq/2.3.aspx
You can't add an attachment simply by specifying the filename. You have to specifically create an attachment object and add that. (as shown in the linked article.)
like this:
mail.Attachments.Add(new Attachment(filename));

Resources