私はsvgオブジェクトをbyte []に変換し、これを次のクラスのキューに格納しています
public class MailMessage
{
public string AttachmentName { get; set; }
public byte[] Attachment { get; set; }
}
ただし、メールは送信されません。メールへの添付ファイルの追加をスキップすると問題なく送信されるため、添付ファイルが破損していると考えています。
using (var stream = new MemoryStream(attachment))
{
var mailMessage = new MailMessage(this.from, new MailAddress(recipient)) { Subject = subject, Body = message };
// this is the line which if commented out allows the email to be sent
mailMessage.Attachments.Add(new Attachment(stream, filename));
MailSender().SendAsync(mailMessage, null);
}
同僚は、ウサギがメッセージを保存する方法が原因で byte[] が侵害された可能性があるため、組み込み関数を使用して保存する前に byte[] を base64 エンコードすることを提案しました。
Convert.ToBase64String(bytes)
Convert.FromBase64String(message.Attachment) // to retrieve
しかし、それもうまくいきませんでした。
これが送信に失敗する理由を誰でも考えて、回避策を考えることはできますか?
画像をデータベースに保存し、電子メールが送信されたら削除することを考えていますが、これは最後のリソースです。