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=...).
Related
I have a complex email template that contains many div, section and other HTML elements. The HTML template has reference to CSS(uploaded to server). I am using the below code to send HTML email via MailKit :
var message = new MimeMessage();
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = File.ReadAllText(pathToHtmlFIle);
message.Body = bodyBuilder.ToMessageBody();
client.Send(message);
But the client only receives everything in plain-text, no colors, no formatting. Is this the expected result ?
I think you need to use either inline CSS or CSS embedded in the head section. Since most webmail clients block links to external stylesheets, it is rare to see this method employed in an email.
After struggling a lot with this topic, I finally figure out the error was the double quotes inside the html...Use notepad++ to replace (quick launched with ctrl+f) all " for '. Holy remedy, after only receiving plain/text I finally received the text/html.
PD: Do not use bootstrap nor try to link an external source 'cause mail clients block external css providers. Use strictly style attributes for all tags.
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
I am generating and sending email using C#.
The mail message is html formatted, and everything appears fine just before the Send method is called i.e. there is only a single dot just before aspx in the href URL, but when I open the sent email in Outlook or any other email client, it shows a double dot for a href as in code below.
<a href='http://localhost/xyz/invitation..aspx?invitecode=92EFB482-1792-4BC6-9507-70D2E3F06FE0'>Click Here </a>
My question: Why would this be happening, and is there any way to resolve this problem like some special encoding for MailMessage.BodyEncoding ? I am using the default encoding (ASCII) for MailMessage.BodyEncoding.
Try using UTF8 encoding. This should work
mail.BodyEncoding = System.Text.Encoding.UTF8;
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.
I'm using MailChimp for .NET sending mails, but the wrapper for the recipient doesn't contain a type, which the is necessary for sending massmails.
MailChimp.Types.Mandrill.Messages.Recipient recipient = new MailChimp.Types.Mandrill.Messages.Recipient(member.EMail, member.Name);
Is it me who has missed something?
Quoted from MailChimp. Scroll down to "Tips for creating your HTML Campaign".
MailChimp does not use a BCC field as each recipient on your list is hidden from all other recipients on your list. We deliver a completely separate copy of your email to each recipient on your list, allowing you to personalize your content for each recipient, track clicks and opens, and address each email to the recipient's name.
I decided to use MCAPI.NET and changed the source adding a attribute to Recipient with name "to".
Setting this attribute to value "BCC" solved the problem.
Note : MailChimp is a Newsletter sending software where Mandrill is a transactional mail sending component.