I have an issue when sending an attachment file that contains Arabic characters which appear as ???? for file name. However, this issue not appear if the file name is English. I tried to use UTF-8 fro encoding but not work.
private static void GenerateAndSendMail(string subject, string body, List<string> filesFullPath = null)
{
try
{
var mailMessage = new MailMessage();
mailMessage.From = new MailAddress(MyAppConfigService.CurrentUser.Email);
mailMessage.Subject = subject;
mailMessage.IsBodyHtml = true;
mailMessage.Body = body;
mailMessage.SubjectEncoding = Encoding.Unicode;
mailMessage.HeadersEncoding = Encoding.Unicode;
mailMessage.BodyEncoding = Encoding.Unicode;
if (filesFullPath != null && filesFullPath.Count > 0)
{
foreach (var item in filesFullPath)
{
var Attachment = new Attachment(item);
Attachment.NameEncoding = Encoding.Unicode;
mailMessage.Attachments.Add(Attachment);
}
}
//save the MailMessage to the filesystem
var filename = Path.GetTempPath() + "mymessage.eml";
mailMessage.Save(filename);
//Open the file with the default associated application registered on the local machine
Process.Start(filename);
}
catch (Exception ex)
{
throw ex;
}
}