[英]Opening the client default mail with attachment
I'm working with asp core mvc project.我正在使用 asp 核心 mvc 项目。 I would like to open the client default mail with a iTextSharp output as an attachment for the email, is this possible using IEmailSender or any other reference?我想打开带有 iTextSharp 输出的客户端默认邮件作为电子邮件的附件,是否可以使用 IEmailSender 或任何其他参考? and if i can empty the fields to,from and keep only the attached file and subject.如果我可以清空字段,从并只保留附件和主题。
[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 });
}
................................................................................................ ………………………………………………………………………………………………………………………………………………………… ……………………………………………………………………………………………………………………………………………………………………………………
Thanks in advance提前致谢
This is not at all possible - and it would be a big security hole if web applications could open our default email client with random files attached (!).这根本不可能 - 如果 Web 应用程序可以打开带有随机文件的默认电子邮件客户端(!),这将是一个很大的安全漏洞。
The mailto
protocol allows you to set the following properties only: mailto
协议仅允许您设置以下属性:
subject
: Text to appear in the subject line of the message. subject
:出现在邮件主题行中的文本。body
: Text to appear in the body of the message. body
: 出现在消息正文中的文本。CC
: Addresses to be included in the "cc" (carbon copy) section of the message. CC
:要包含在邮件“抄送”(抄送)部分中的地址。BCC
: Addresses to be included in the "bcc" (blind carbon copy) section of the message. BCC
:要包含在消息的“bcc”(密件抄送)部分中的地址。 One possible idea would be to allow your users to upload files to your website first, and you create a mailto:
link that includes the URL of the file they uploaded in the body of the email message.一种可能的想法是让您的用户首先将文件上传到您的网站,然后您创建一个mailto:
链接,其中包含他们在电子邮件正文中上传的文件的 URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.