Sending an email to outlook with emoji characters using C# - c#

I have a user input on a web page.
They are able to type a message and send.
The message gets sent to them via SMTP and the client they'll be using is outlook.
The problem I am getting is that emoji [😂🐱‍👓🤷‍♂️👍] are coming through as varying amount of ?? question marks.
There's also a number of problematic characters that come through when they paste content from work like special quotes and the em dash which is often substituted in word when people type a dash.
I know outlook supports emoji as I can type them in with Windows + ; and send them fine. But this is getting mangled somehow when I send it through the SMTP client.
Debugging is showing the emoji correctly before sending it through the SMTP client.
Any ideas what I need to do to get it to send without resorting to stripping these characters out? I'd like for people to be able to use these emoji if they like.

Thanks to #Steve for making me reconsider the obvious 🙌
Turns out all I needed to do was set the BodyEncoding to System.Text.Encoding.UTF8 on the message.
Setting the IsBodyHtml property to true was not enough.
Not sure what the default is for this to not work without setting it to UTF8 but oh well.
mail.BodyEncoding = System.Text.Encoding.UTF8;
https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.mailmessage.bodyencoding

Related

C# MailKit - How to create a Rtf message

I'm trying to send a message in rtf format but on reception it is not interpreted correctly by gmail, etc. (except Mail.app on MacOS). Here is a sample code. Some client application consider it as "text".
String body = #"{\rtf1\ansi\deff0{\colortbl;\red0\green0\blue0;\red255\green0\blue0;} This line is the default color\line \cf2 This line is red\line \cf1 This line is the default color}"
message.Body = new TextPart("rtf") { Text = body };
Where am I wrong?
As jdweng points out, most mail clients do not support RTF.
Google mail only supports HTML and plain-text messages as far as I know.
I tried testing this by using Outlook to send an RTF message to GMail, but alas, my Exchange server always overrides the RTF by converting it to HTML and so GMail always receives text/html instead of text/rtf.
I might be able to get Outlook to send text/rtf if I configure it to send via some non-Exchange account, but I'm too lazy to bother.

Problem with special character when using c# api

i have a problem with using character when i want to get user information by using email
the problem is special character in the email
because the api link not supports character for example
this is the Route im using in the api
[Route("api/v1/Users/{Email}")]
and this is the link
api/v1/Users/majed email.com
any special character let the GET not even see the request link
how can i solve this problem ?!
In most scenarios it has been found that a 404 is returned if an email address is sent. The issue is usually caused by the "." in the email address.
If you add a trailing slash it should resolve your issue.
api/v1/Users/majed#email.com/
You could use URL encoded format of the string.
The string majed#email.com would encoded be majed%40email.com.
You can read more at W3 Shools URL Encoding Reference.

sending an email to hotmail inbox

I am trying to send an email using c# MailMessage to a hotmail account but the emails are always going to junk.
How can i send emails directly to hotmail inbox in c#?
I don't have my own smtp server, therefore i have tried using my university smtp and other smtps like google, yahoo... but all emails were sent to junk.
Any solutions?
This is not really a C# question.
Mails are sent to spam depending on their content and their headers so you should check a few things :
You need to have a subject
you shouldn't have spammy words (sex, viagra, love, watches)
You need to have a return-to and a from address headers that match
You need to be consistent with your encoding, if you go for UTF8 send UTF8 text
You shouldn't insert images
Your links inside the mail, if any, should have their text set to the address they are going to
Using these strategies should help your email not being classified as spam.
You can always check the headers of one of the mail that went into spam. It is often described what rules were applied and where the mail failed.
In hotmail, open the Junk folder, click on the message. Hotmail will display options in the body of the message - click on "Wait, it's safe!" Hotmail will move the message to your inbox, and mark the FROM email address as safe.
There is (probably) nothing wrong with your code - it is hotmail identifying the sender and/or subject as being junk.
Although it may well be out of your control, junk email filters generally work on a weighting system, so there are things that you can do to make your email look less like spam.
To start with, check that:
your subject doesn't contain all caps or sensitive words (such as "FREE!")
your body has content
the 'from' address for the MailMessage exists.
If those are all fine, have a look through this list, this article on live.com and the Policies, Practices and Guidelines for Hotmail.
What is the content of your mail, is it text that is likely to be regarded as junk mail by spam filters? Have you tried sending to other accounts such as Yahoo or Gmail?
You can't do it from C#.
It is up to the recipient to route the messages to junk or inbox or wherever it decides to put the message. If the sender were allowed to decide where the message went on the client's side, imagine how much bigger of a problem spam would be.
One solution you can employ is to have your target mail account 'whitelist' the sender, but that may not be an option in all cases.

Sending Fax using SMTPClient?

We have a exchangeserver configured to send the attachment of a email as fax if the the "to-address-field" is in the format [fax:user/company#faxnumber] (used internally). It works when I send manually from Outlook. But how can send an email with to-address as above using Smtpclient?
Is it possible to suppress the emailaddress validation? at the moment i get this error:
"System.FormatException : The specified string is not in the form required for an e-mail address."
I'm fairly sure that it's not possible. However, at least in .Net 4.0 (which is less restrictive than earlier versions), everything except the : is fine though. Maybe you could get the admins to change the SMTP server to support other characters than : after the string fax?
For example, maybe you could use fax= instead.
It is not possible through the SmtpClient. If fax=asdfasdf is wanted then going through interop.outlook.dll is needed.

Sending html emails from C#

I'm trying to send an html email to a gmail account, but for some reason, Google is stripping away the html from my email. The Html is preserved when I send to other accounts (non-gmail accounts) so I know that my html is correct.
Here's how I'm going about it:
I have an aspx page, that I use as an email template.
I grab the html from the aspx page from within a web service (done in C#)
Dynamically fill in the non-static content through c# code within the web service.
Send that as the email body.
Does anyone happen to know why gmail is removing the html?
Thanks in advance.
You need to be sure to set the IsBodyHtml property to true on your MailMessage:
var message = new MailMessage();
message.IsBodyHtml = true;
// Fill and send message here
Check out the MSDN reference for more info:
System.Net.Mail.MailMessage Members
The Html is preserved when I send to other accounts (non-gmail accounts) so I know that my html is correct.
It's not a programming issue. If it were, as you've observed, this would happen to all clients.
The issue is this: Most modern email clients allow users to choose to disallow html messages, or always view them as plain text. That could be what is happening here. You have to code to expect this, because you can't control user's preferences. If they have this enabled, and you send it as html only, it will look ugly to them.
However, for a solution to your issue, you should always be sending your mail as a Multi-Part Mime message to allow all clients to get a nice readable version.

Categories