I'm trying to send an email with attachment of self-defined file extension name, like 'file.aaa'. I don't know how to set it's MIME content type. I new an atachment as 'new Attachement(stream, null, null)'. But then got an Amazon exception of 'Illegal file name file.aaa'.
質問する
259 次
1 に答える
0
電子メールで MIME タイプを指定する必要があります。を使用して、テキスト ファイルapplication/octet-stream
のバイナリ ファイルとして処理する必要があることを指定できます。詳細については、ウィキペディアの記事を参照してください。text/plain
application/vnd.yourcompany.yourapplicationname
type/vnd.company
どうやら、Amazon はファイル拡張子と MIME タイプの両方を制限しているようです。どうやら許可されているように、カスタム形式を圧縮することを検討します。詳細については、開発者向けドキュメントを参照してください。
var inputfile = "foobar.aaa";
var tempdir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
var outZipFile = File.GetTempFileName();
File.Move(inputfile, tempdir);
ZipFile.CreateFromDirectory(tempdir, outZipFile);
Directory.Delete(tempdir, true /* delete the file within */);
var attachment = new Attachment(outZipFile, "yourFile.zip", "application/octet-stream");
// send your email
File.Delete(outZipFile);
于 2013-11-05T00:09:52.727 に答える