c# 发送到附件的电子邮件对象

发布于 2024-10-10 14:56:33 字数 631 浏览 0 评论 0原文

我正在尝试从一个列表列表对象创建并发送电子邮件附件。我找到了一个记录良好的答案 在这里,但仍然有一些困惑。

它提到“获取一些二进制数据”,

//Get some binary data
byte[] data = GetData();

我已经通过以下方式测试了我的数据:

Console.WriteLine(ieLog.FirstName + "." + ieLog.LastName);

我想我的问题是,如果它还不是流,那么如何将其转换为流,然后使用:

//save the data to a memory stream
MemoryStream ms = new MemoryStream(data);

然后发送附件?

感谢您的任何帮助或提示。

如果我无法弄清楚,我想成为 Excel 文档或 csv。我确信已经有此类内容的课程,新手在哪里寻找此类信息?

I'm trying to create and send an email attachment from an object which is a list of lists. I found a nicely documented answer here, but still have some confusion.

It mentions "get some binary data"

//Get some binary data
byte[] data = GetData();

I have tested my data by:

Console.WriteLine(ieLog.FirstName + "." + ieLog.LastName);

I guess my question is how do I turn that into a stream if it isn't already one and then use:

//save the data to a memory stream
MemoryStream ms = new MemoryStream(data);

and then send the attachment?

Thank you for any help or hints.

I would like to be an excel doc or csv if I can't figure that out. I'm sure there are already classes for this sort of thing, where does a newb look for that sort of information?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄居者 2024-10-17 14:56:33

我是直接在浏览器中写的,不过应该没问题:

...

byte[] data = ASCIIEncoding.Default.GetBytes(ieLog.FirstName + "." + ieLog.LastName);

using(MemoryStream ms = new MemoryStream(data))
{
    mail.Attachments.Add(new Attachment(ms, "myFile.csv", "text/csv" ));

    SmtpClient smtp = new SmtpClient("127.0.0.1");
    smtp.Send(mail);   
}

I wrote it directly in the browser, but it should be ok:

...

byte[] data = ASCIIEncoding.Default.GetBytes(ieLog.FirstName + "." + ieLog.LastName);

using(MemoryStream ms = new MemoryStream(data))
{
    mail.Attachments.Add(new Attachment(ms, "myFile.csv", "text/csv" ));

    SmtpClient smtp = new SmtpClient("127.0.0.1");
    smtp.Send(mail);   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文