In an ASP.NET MVC5 C# application I am using the standard code for sending confirmation emails when a user registers, something I've done in multiple projects:
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking here");
Normally when the recipient receives the email, it's content-type is text/html. However, in this one application, the emails arrive with content-type text/plain and the content is not rendered as html, it is rendered as plain text. It should like this:
Please confirm your account by clicking here
But it looks like this:
Please confirm your account by clicking here
I searched the docs but cannot find any information that indicates why this would be or indeed how to change this behavior.
I also updated to the latest version of the Microsoft ASP.NET Identity Core (2.2.1) thinking that might help, but it didn't have any effect on the issue.
I also tested sending from a Google Apps email account for a different organization (which I use for other apps with this exact same code to send this confirmation email and know it sends as html) in case there are some settings in there that matter.
Any ideas on why it sends as text/plain and how I can fix this?
Thanks!
The problem more than likely isn't with your Identity, it is probably just with the mail function itself. Have you set the MailMessage.IsBodyHtml property to true?
MailMessage message = new MailMessage(fromEmail, toEmail, subject, body);
message.IsBodyHtml = true; // here
This will set the body of the email to be rendered as HTML. By default, the property is false, so you need to explicitly declare it to be true.
The issue is likely with the mail service/api you're using. I have used several and they generally have either an optional htmlBody parameter or an isBodyHtml parameter. If you specify which one you're using, or provide the code for the SendAsync Methos in the EmailService class (in IdentityConfig.cs), it'll probably be easy to point you in the right direction.
If your stuck with plain text, you can send plain text with a url and the client will often convert it into a link for the user. Outlook and gmail do this.
So, it would look like this instead:
await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account:" + callbackUrl);
You can use SendGrid API to send HTML type emails and they also provide transactional templates.
Links
https://sendgrid.com/
Even advised in the Asp.net core doc
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm?view=aspnetcore-2.2&tabs=visual-studio
Related
Introdution
I am currently working a system develop with C#.
The system is about request approval.
When a request made, system will send email to user ask for response.
User's response will as simple as approve, reject or request update.
Question/Problem
Is it possible to have a button (approve or reject) in email content which allow user to response to system with only one click but without open browser?
Or, Is it possible to create button in email content which enable user to click to create new email with pre-set subject and recipient like following:
subject: request id - 123 - action - approve
to: response#system.com
as response email for user to send.
Then system can then recognize the email received and perform required back-end process.
Research Done
Research 1
What I currently found was outlook appointment email.
it done like second solution create new email with content for user send a response.
But, it only have options accept, decline and tentative.
And, I am not sure is blackberry support it like outlook.
The following is the blog found to create appointment email:
http://chuckdotnet.blogspot.my/2007/10/send-outlook-meeting-requests-with.html
Research 2
The following website teach you how to create hyperlink in email content which can create new email with pre-populate subject, body, and recipient
https://community.articulate.com/discussions/building-better-courses/hyperlink-to-create-an-already-written-email
However, No test had perform in blackberry yet.
Appreciate for any suggestion from you guys and I willing to try.
Is it possible to sent an email with button which can click to create
email with some pre-set content?
Yes, this is possible, see the System.Net.Mail code in the .NET framework.
https://msdn.microsoft.com/en-us/library/system.net.mail(v=vs.110).aspx
You can also see this StackOverflow question about how this is used.
Send e-mail via SMTP using C#
MailMessage mail = new MailMessage("you#yourcompany.com", "user#hotmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
Finally, your code should fire a serverside post on button click to have the server take care of sending the email. If data needs to be posted to the server, you may want to consider putting this data in a form input, which will post to your controller. You can then take that data and build the email with the example I provided in the links.
Is there a way to send a http link in a wp8 app? I'm using
EmailComposeTask emailComposeTask = new EmailComposeTask();
but whenever I include an http link in the body of my email, it just appears as regular text.
My http link is included in a default string, so it would kind of make sense, but I assumed that the email app receving the email would just detected the http://... and automatically converted it a link but that's not the case.
Should I include the http link within a specific tag??
Any ideas?
Thanks
You Would see link as normal Text in Body when Composing but in mail it would be seen highlighted as link
Try this :
EmailComposeTask task = new EmailComposeTask();
task.To = "Set Email here";
task.Subject = "Subject goes here";
task.Body = "Your Mesage goes here \n http://www.google.com";
task.Show();
I have attached Screen Capture of inbox.
When you called EmailComposeTask, It will show an mail edit page.
In this page, the http link can't be shown.
But when you send it, in the Sent folder, the mail can show http link.
And in the receiver's Inbox, it also can be shown.
My team and I have a very specific and frustrating issue. We have an MVC4 web application that many people utilized within a company (no external exposure). Some of our processes generate emails to other employees with links back to the application.
For example, there may be some activity that one employee sees and wants to attend. They can can an email to the other employee saying they would like to attend.
In these emails, we put an anchor tag in with the link back to our application and some query string stuff to help direct it to the right page.
All of that works wonderfully. Now, the problem is, we want the link (from the email) to load in an existing window with the application, if it exists. Normally, I believe, this would be done with setting the target attribute in the anchor tag, but that doesn't work, it just opens in a new tab.
This is what the anchor tag source from the email looks like (i've changed some text so that it hides company related info):
Please <a target="appMain" href='http://domain/app/controller.aspx/view?
keyname=querystringparam1¶ms={"prop1":val,"prop2":va;}'>
click here</a> to approve and go to app
this is our smtp function to send the mail:
public void SendMail(EmailContent emailContent, string mailConfigurationPath)
{
var toRecipients = string.Join(",", emailContent.ToList);
var mailMessage = new MailMessage(emailContent.From, toRecipients)
{
IsBodyHtml = emailContent.IsBodyHtml,
Body = emailContent.Body,
Subject = emailContent.Subject
};
var smtpClient = new SmtpClient
{
DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory,
PickupDirectoryLocation = mailConfigurationPath
};
smtpClient.Send(mailMessage);
}
Is what I'm trying to achieve even possible? It seems pretty straight forward, maybe I'm just going about it the wrong way. Would love some help or even some "crazy" ideas.
This is not possible, because it creates a vulnerability in the email program itself...
http://thenextweb.com/insider/2013/01/07/yahoo-mail-users-hit-by-widespread-hacking-xss-exploit-seemingly-to-blame/
Also, it goes against all the normal user interface guidelines for email programs. Users don't expect an email to transform into an app. They are very familiar with clicking on links in emails though, so you wouldn't want that action to do something weird.
I am sending an email with System.Net.Mail and I want to protect my user from receiving urls through those emails.
I have already used HtmlEncode and it works if my form data is html or script but if the user types a normal url (e.g. www.stackoverflow.com) or an email address, the e-mail body itself creates a link - even though I set IsBodyHtml to false.
I would like to know how I could ensure that my entire email body text cannot be clicked and taken somewhere else.
Ps: I tried using UrlEncode but it 'breaks' the entire email message.
This is caused by the email client (Outlook, Gmail, etc.) parsing the URL for your convenience. If you look inside the Body property of the MailMessage object, you would have no HTML link (<a href=...).
I am creating a sample Win8 app and using share contract I am trying to share HTML Content. When the user select email app from the share application option I want to set email address in TO field. How can I do so? Following is my code written to share HTML content:
Code:
DataPackage requestData = request.Data;
requestData.Properties.Title = this.PageViewModel.JobInformationDetail.JobNumber;
requestData.Properties.Description = this.PageViewModel.JobInformationDetail.CustomerSignatureName;
//requestData.SetText("Sample Text");
StorageFile signatureStream = await GetInkManagerStream();
requestData.SetHtmlFormat(Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.CreateHtmlFormat(this.GetMailDescription()));
Following images shows where to set the email address in To field:
You can't do that. We'll have a solution to this until WinRT come up with a standard email DataPackage format to StandardDataFormats and support it in the email app.
I think Microsoft's default Mail should be upgraded. It's entirely depend upon sharing target app to show particular data to particular place. DataPackage's Title property is set as subject and Description property is set as mail body but there's no provsion for to email(s).
If sharing experience is best one then user will user default Mail app otherwise they will go for another mail apps.