I have a service which creates Excel file and sends by email.
So I have a strange trouble. This service works correctly on a test server but on a production server I have a bug - there is strange file in attachments without extension with name like this "=utf-8B0J3QtdC0YDQvtGB0YLQsNCy0LvQtdC9" and the same content inside insted of a excel file.
There is my sending method. I suppose that there are trubles not in my code. I would be very grateful if somebody can help me.
public static void SendEmail(string subject, string body, string recipients, Attachment attachment = null)
{
string mailServer = Settings.Default.MailServer;
MailMessage message = new MailMessage(Settings.Default.MailSender, recipients);
foreach (string address in Settings.Default.MailCopyTo.Split(',').Select(x => x.Trim()))
{
if (!string.IsNullOrEmpty(address))
message.CC.Add(new MailAddress(address));
}
message.IsBodyHtml = true;
message.Body = body;
message.Subject = subject;
if(attachment != null)
message.Attachments.Add(attachment);
SmtpClient client = new SmtpClient(mailServer);
var AuthenticationDetails = new NetworkCredential(Settings.Default.MailLogin, Settings.Default.MailPassword);
client.Credentials = AuthenticationDetails;
client.Send(message);
}
Aucun commentaire:
Enregistrer un commentaire