对,我正尝试通过莲花笔记发送电子邮件表单,它具有附件,正文需要使用HTML。
我已经阅读了一些代码,可以让我做到这一点,但事实并非如此。没有HTML正文,附件将发送,当我隐含HTML正文时,电子邮件仍然发送,但附件消失了
try
{
Session.Initialize("1234567890");
Session.ConvertMime = false;
MailServer = Session.GetEnvironmentString("MailServer", true);
MailFile = Session.GetEnvironmentString("Mailfile", true);
MailDb = Session.GetDatabase(MailServer.ToString(), MailFile.ToString(), false);
MailDoc = MailDb.CreateDocument();
MailDoc.ReplaceItemValue("Form", "Memo");
MailDoc.ReplaceItemValue("SendTo", "XXXXXX");
MailDoc.ReplaceItemValue("subject", "Test test");
MailDoc.AppendItemValue("Principal", "HIHIHi");
object obAttachment;
Mime = MailDoc.CreateMIMEEntity("Body");
HtmlBody = Session.CreateStream();
HtmlBody.Open("C:\\Users\\Documents\\310143-001_1125_20181016.pdf", "");
Mime.SetContentFromBytes(HtmlBody, "Application/pdf", Domino.MIME_ENCODING.ENC_IDENTITY_BINARY);
HtmlBody.Close();
HtmlBody.Truncate();
HtmlBody = Session.CreateStream();
HtmlBody.WriteText(mailBoby, EOL_TYPE.EOL_CR);
Mime.SetContentFromText(HtmlBody, "text/html;charset=UTF-8", Domino.MIME_ENCODING.ENC_IDENTITY_BINARY);
Object obj = MailDoc.GetItemValue("SendTo");
MailDoc.SaveMessageOnSend = true;
MailDoc.Send(false, ref obj);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
rt = null;
Session = null;
MailDoc = null;
MailDb = null;
}
答案 0 :(得分:0)
您要在Mime对象上两次调用SetContentFromBytes和SetContentFromText方法。在同一Mime对象上。第二个调用将覆盖第一个。
您需要使用CreateChildEntity method创建MIME实体树,将父实体的内容类型设置为'multipart',并将其中一个子实体设置为文本,将其中一个实体设置为附件。
答案 1 :(得分:0)
您必须为HTML和文件附件创建一个多部分的MIME消息。
Session.Initialize("1234567890");
Session.ConvertMime = false;
MailServer = Session.GetEnvironmentString("MailServer", true);
MailFile = Session.GetEnvironmentString("Mailfile", true);
MailDb = Session.GetDatabase(MailServer.ToString(), MailFile.ToString(), false);
MailDoc = MailDb.CreateDocument();
MailDoc.ReplaceItemValue("Form", "Memo");
MailDoc.ReplaceItemValue("SendTo", "XXXXXX");
MailDoc.ReplaceItemValue("subject", "Test test");
MailDoc.AppendItemValue("Principal", "HIHIHi");
object obAttachment;
AttachmentPath = "C:\\Users\\Documents\\";
AttachmentFile = "310143-001_1125_20181016.pdf";
mailBody = "<html><head></head><body>Hello There.</body></html>";
Mime = MailDoc.CreateMIMEEntity("Body");
MimeHeader = Mime.CreateHeader("MIME-Version");
MimeHeader.SetHeaderVal("1.0");
MimeHeader= Mime.CreateHeader("Content-Type");
MimeHeader.SetHeaderValAndParams( "multipart/alternative;boundary=\"=NextPart_=\"");
MimeChild = Mime.CreateChildEntity();
HtmlBody = Session.CreateStream();
HtmlBody.WriteText(mailBody, Stream.EOL_CR);
MimeChild.SetContentFromText(HtmlBody, "text/html;charset=\"iso-8859-1\"", Domino.MIME_ENCODING.ENC_NONE);
MimeChild = Mime.CreateChildEntity();
HtmlBody = Session.CreateStream();
HtmlBody.Open(AttachmentPath + AttachmentFile, "");
MimeHeader = MimeChild.CreateHeader("Content-Disposition");
MimeHeader.SetHeaderVal("attachment; filename=\""+AttachmentFile+"\"");
MimeChild.SetContentFromBytes(HtmlBody, "application/octet-stream; name=\""+AttachmentFile+"\"", Domino.MIME_ENCODING.ENC_IDENTITY_BINARY);
MailDoc.CloseMIMEEntities(true);
Session.ConvertMime = true;
Object obj = MailDoc.GetItemValue("SendTo");
MailDoc.SaveMessageOnSend = true;
MailDoc.Send(false, ref obj);
这对大多数文件类型都适用,但是您可以为PDF文件的application/pdf
指定Content-Disposition
。