【问题标题】:How to generate email from byte array and add attachment to it如何从字节数组生成电子邮件并添加附件
【发布时间】:2017-04-28 07:35:12
【问题描述】:

我正在开发一个 asp.net 应用程序。它有以下方法:

private bool SaveDocumentFile(string FilePath, string FileName, byte[] Data)
        {
            BinaryWriter Writer = null;
            string Name = "";
            try
            {    
                Name = FilePath + "\\" + FileName;

                // Create a new stream to write to the file
                Writer = new BinaryWriter(File.OpenWrite(Name));

                // Writer raw data                
                Writer.Write(Data);
                Writer.Flush();
                Writer.Close();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message + " SaveDocumentFile Exception");
                return false;
            }

            return true;
        }

FileName 参数可以是 word、PDF 或 email 格式。

如果文件名包含 .msg 扩展名,字节数组将包含详细信息,例如发件人、收件人、电子邮件主题、电子邮件正文等。函数将以 .msg 扩展名保存文件。如果我在 Outlook 中打开保存的文件,它将填充从、到、主题和正文字段。

现在我想添加一个条件,以便每当文件格式为 .msg 时,SaveDocumentFile 函数应将存储在公共位置的文件夹中的附件添加到 .msg 文件中。

这可以实现吗?如果是怎么办?任何帮助将不胜感激!

【问题讨论】:

  • “SaveDocumentFile”函数应该做什么?添加附件到什么?
  • 它应该将附件添加到 .msg 文件中。我更新我的问题。谢谢。

标签: asp.net .net email email-attachments email-client


【解决方案1】:

使用MSG.NET(不是免费的)。见add attachement tutorial

using Independentsoft.Msg;

Message message = new Message("c:\\temp\\message.msg");
Attachment attachment = new Attachment("c:\\temp\\test.pdf");
message.Attachments.Add(attachment);
message.Save("c:\\temp\\message.msg", true);

【讨论】:

    猜你喜欢
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    相关资源
    最近更新 更多