打开带有附件的客户端默认邮件

Opening the client default mail with attachment

我正在处理 asp 核心 mvc 项目。我想打开带有 iTextSharp 输出的客户端默认邮件作为电子邮件的附件,是否可以使用 IEmailSender 或任何其他参考? 如果我可以清空字段,从中只保留附件和主题。

[HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> GeneratePDF(int? id)
        {
            var webRootPath = _hostingEnvironment.WebRootPath;
            var path = Path.Combine(webRootPath, "DataDump"); //folder name
            var story = await _db.Story.Include(s => s.Child).Include(s => s.Sentences).ThenInclude(s => s.Image).FirstOrDefaultAsync(s => s.StoryId == id);


            using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
            {
                iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10, 10, 10, 10);
                PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
                document.Open();

                string usedFont = Path.Combine(webRootPath + "\Fonts\", "Dubai-Light.TTF");
                BaseFont bf = BaseFont.CreateFont(usedFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                iTextSharp.text.Font titleFont = new iTextSharp.text.Font(bf, 20);
                iTextSharp.text.Font sentencesFont = new iTextSharp.text.Font(bf, 15);
                iTextSharp.text.Font childNamewFont = new iTextSharp.text.Font(bf, 17);

                PdfPTable T = new PdfPTable(1);
                //Hide the table border
                T.DefaultCell.BorderWidth = 0;
                T.DefaultCell.HorizontalAlignment = 1;
                //Set RTL mode
                T.RunDirection = PdfWriter.RUN_DIRECTION_RTL;

                //Add our text
                if (story.Title != null)
                {
                    T.AddCell(new iTextSharp.text.Paragraph(story.Title, titleFont));
                }
                if (story.Child != null)
                {
                    if (story.Child.FirstName != null && story.Child.LastName != null)
                    {
                        T.AddCell(new iTextSharp.text.Phrase(story.Child.FirstName + story.Child.LastName, childNamewFont));
                    }
                }
                if (story.Sentences != null)
                {
                    foreach (var item in story.Sentences)
                    {
                        if (item.Image != null)
                        {
                            var file = webRootPath + item.Image.ImageSelected;
                            byte[] fileBytes = System.IO.File.ReadAllBytes(file);
                            iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(fileBytes);
                            pic.ScaleAbsoluteWidth(25f);
                            T.AddCell(pic);

                        }
                        else
                        {
                            T.AddCell(new iTextSharp.text.Phrase("no image", sentencesFont));
                        }
                        T.AddCell(new iTextSharp.text.Phrase(item.SentenceText, sentencesFont));
                    }
                }
                document.Add(T);
                document.Close();

                byte[] bytes = memoryStream.ToArray();
                var fileName = path + "\PDF" + DateTime.Now.ToString("yyyyMMdd-HHMMss") + ".pdf";

                using (FileStream fs = new FileStream(fileName, FileMode.Create))
                {
                    fs.Write(bytes, 0, bytes.Length);
                }
                memoryStream.Close();
                //Send generated pdf as attchment
                
                //Remove form root
                if (System.IO.File.Exists(fileName))
                {
                    System.IO.File.Delete(fileName);
                }

            }
            return RedirectToAction("Details", new { id = id });
        }

................................................ ..................................................... .

提前致谢

这根本不可能 - 如果 Web 应用程序可以打开我们带有随机附件 (!) 的默认电子邮件客户端,那将是一个很大的安全漏洞。

mailto 协议仅允许您设置以下属性:

  • subject:显示在邮件主题行中的文本。
  • body:显示在邮件正文中的文本。
  • CC:要包含在邮件“抄送”(抄送)部分中的地址。
  • BCC:要包含在邮件“密件抄送”(密件抄送)部分的地址。

一个可能的想法是让您的用户先将文件上传到您的网站,然后您创建一个 mailto: link,其中包含他们上传的文件的 URL电子邮件正文。