简体   繁体   English

在 Asp.net/C# 中发送带有附件的电子邮件 - Gmail 的问题

[英]Sending email in Asp.net / C# with attachments - Issues with Gmail

In an ASP/C# application I'm sending an email with 3 file attached.在 ASP/C# 应用程序中,我发送了一封附有 3 个文件的电子邮件。 The 3 files are the same type, same extension and more or less same size ( but none are empty ).这 3 个文件具有相同的类型、相同的扩展名和大致相同的大小(但没有一个是空的)。 The email is sent correctly.电子邮件已正确发送。 If I open it using outlook, I have no problems.如果我使用outlook打开它,我没有问题。 I can see the body, and the 3 files attached.我可以看到正文和附加的 3 个文件。

But here is my issue: If I send that mail to a Gmail Adress, then on Gmail I can see only 2 attachments.但这是我的问题:如果我将该邮件发送到 Gmail 地址,那么在 Gmail 上我只能看到 2 个附件。

在此处输入图片说明

And if I click on the download all attachment icon ( on the right ), it will download the 2 visible attachment + the third one but empty.如果我单击“下载所有附件”图标(右侧),它将下载 2 个可见附件 + 第三个但为空的附件。

It's a really weird issue.真是个奇怪的问题。

Also there is a 4th attachment which is an embedded image.还有第四个附件是嵌入的图像。 And this image is display correctly in the mail body.并且此图像在邮件正文中正确显示。

Here is the code I'm using to send the mail:这是我用来发送邮件的代码:

            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("SMTP_IP_ADRESS", SMTP_IP_PORT);

            mail.From = new MailAddress("MYEMAIL@DOMAIN.COM");

            mail.To.Add("GMAIL_EMAIL");
            mail.To.Add("OUTLOOK_EMAIL");

            mail.Subject = "MSN "+Request.Params["nameMsn"];

            Attachment imageAttachment = new 
            Attachment(Server.MapPath(Url.Content("~/Content/images/image.png")));
            string contentID = "logoCare";
            imageAttachment.ContentId = contentID;
            mail.IsBodyHtml = true;
            mail.Body = "<html><body>Have a good day.<br/>Best regards. <br/><br/><img width='200' 
            src=\"cid:"
                 + contentID + "\"></body></html>";

            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i];
                var attachment = new Attachment(file.InputStream, file.FileName, 
                MediaTypeNames.Application.Octet);
                mail.Attachments.Add(attachment);
            }

            mail.Attachments.Add(imageAttachment);

            SmtpServer.Send(mail);

The third attachment you see empty can possibly be the CID embedded image that web based email clients (like Gmail) can't manage, meanwhile it works with desktop email clients like Outlook.您看到的第三个空白附件可能是基于 Web 的电子邮件客户端(如 Gmail)无法管理的 CID 嵌入图像,同时它可以与 Outlook 等桌面电子邮件客户端一起使用。 Can you verify this?你能验证一下吗? Please take a look at here请看这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM