gpt4 book ai didi

c# - 为什么真实的电子邮件大小比我的附件和文本大小大?

转载 作者:太空宇宙 更新时间:2023-11-03 11:05:17 25 4
gpt4 key购买 nike

我有简单的代码来发送带附件的电子邮件:

using (MailMessage mail = new MailMessage())
{
using (SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"))
{

mail.From = new MailAddress("my_mail@gmail.com");
mail.Sender = new MailAddress("my_mail@gmail.com");
mail.To.Add("my_mail@gmail.com");
mail.Subject = "TEST";
mail.Body = "Test body message";

//Add attachment
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("1568817207ComputationC.part1.rar"); //Size 24MB
mail.Attachments.Add(attachment);

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("my_mail@gmail.com", "password");

SmtpServer.EnableSsl = true;
SmtpServer.Timeout = 0;

SmtpServer.Send(mail);
}
}

我的附件大小为 24MB + 一些文本 = 最大 25MB

我通过 gmail 收件箱中的“显示原始”选项测量了邮件的实际大小,然后将此邮件下载到我的硬盘。

此外,当我测量我的应用发送电子邮件时发送了多少字节时,它显示 33MB。

所以,我的问题是为什么当我的附件 + 文本 = 最大 25MB 时这封电子邮件的实际大小是 33MB :D?

最佳答案

因为你的邮箱是MIME encoded - 二进制数据从 8 位数据更改为(通常)7 位数据,以便在服务器之间可靠地传输。有几种不同的编码方案,但它们通常会给电子邮件的大小增加 33% 的开销 - 因此 25Mb 的电子邮件实际上是 32.5Mb 的数据。

编辑:This page Base64编码有很好的解释,一般发邮件的时候会用到:

The number of output bytes per input byte is approximately 4 / 3 (33% overhead) and converges to that value for a large number of bytes. More specifically, given an input of n bytes, the output will be 4[n/3] bytes long, including padding characters.

关于c# - 为什么真实的电子邮件大小比我的附件和文本大小大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16120550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com