代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.Net
】
如何在邮件正文粘贴图片
作者:
sky3010
/ 发布于
2014/6/5
/
520
过.net应用程序调用Lotus Notes的COM组件来实现自动发送邮件的小程序,现在需要在邮件正文直接显示图片,而不是以附件的方式发送图片
public Boolean SendNotesMail(object To, object copyTo, string subject, string location) { string from = ConfigurationManager.AppSettings["from"]; Domino.NotesSession ns = null; Domino.NotesDatabase nd = null; Domino.NotesDocument nDoc = null; Domino.NotesMIMEEntity mime = null; Domino.NotesMIMEHeader mimeHeader = null; Domino.NotesMIMEEntity child = null; NotesStream stream = null; object itemValue = null; string pw = ""; string serverName = ""; string mailFile = ""; string date = System.DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); string[] sImage = { "pic1.gif", "pic2.gif", "test.xlsx" }; string sHtml = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" align=\"left\">" + "<tr><td><img src=\"cid:" + sImage[0] + "\"></td></tr><tr><td><img src=\"cid:" + sImage[1] + "\"></td></tr></table>"; try { lock (this) { ns = new Domino.NotesSession(); pw = ConfigurationManager.AppSettings["fromPW"]; ns.Initialize(pw); serverName = ConfigurationManager.AppSettings["mailServer"]; mailFile = "mail\\" + ConfigurationManager.AppSettings["fromJobcode"]; nd = ns.GetDatabase(serverName, mailFile, false); if (!nd.IsOpen) { nd.Open(); } nDoc = nd.CreateDocument(); nDoc.ReplaceItemValue("Form", "Memo"); nDoc.ReplaceItemValue("From", from); nDoc.ReplaceItemValue("SendTo", To); nDoc.ReplaceItemValue("CopyTo", copyTo); nDoc.ReplaceItemValue("Subject", subject); stream = ns.CreateStream(); mime = nDoc.CreateMIMEEntity("Body"); mimeHeader = mime.CreateHeader("Content-Type"); mimeHeader.SetHeaderVal("multipart/related"); //发送HTML格式文本 child = mime.CreateChildEntity(null); stream.WriteText(sHtml,EOL_TYPE.EOL_NONE); child.SetContentFromText(stream, "text/html;charset=gb2312", MIME_ENCODING.ENC_NONE); stream.Close(); //发送图片 child = mime.CreateChildEntity(null); mimeHeader = child.CreateHeader("Content-ID"); mimeHeader.SetHeaderVal(sImage[0]); if (stream.Open(Directory.GetCurrentDirectory() + "[url=file://\\pic\\]\\pic\\[/url]" + sImage[0], "binary")) { if (stream.Bytes != 0) child.SetContentFromBytes(stream, "image/jpeg;name=\"" + sImage[0] + "\"", MIME_ENCODING.ENC_IDENTITY_BINARY); } stream.Close(); child = mime.CreateChildEntity(null); mimeHeader = child.CreateHeader("Content-ID"); mimeHeader.SetHeaderVal(sImage[1]); if (stream.Open(Directory.GetCurrentDirectory() + "[url=file://\\pic\\]\\pic\\[/url]" + sImage[1], "binary")) { if (stream.Bytes != 0) child.SetContentFromBytes(stream, "image/jpeg;name=\"" + sImage[1] + "\"", MIME_ENCODING.ENC_IDENTITY_BINARY); } stream.Close(); //添加附件 child = mime.CreateChildEntity(null); mimeHeader = child.CreateHeader("Content-Type"); mimeHeader.SetHeaderVal("multipart/related"); mimeHeader = child.CreateHeader("Content-Disposition"); mimeHeader.SetHeaderVal("attachment;filename=\"" + "Tempeture.gif" + "\""); mimeHeader = child.CreateHeader("Content-ID"); mimeHeader.SetHeaderVal(sImage[0]); if (stream.Open(Directory.GetCurrentDirectory() + "[url=file://\\pic\\]\\pic\\[/url]" + sImage[0], "binary")) { if (stream.Bytes != 0) child.SetContentFromBytes(stream, "application/octet-stream" + "\"", MIME_ENCODING.ENC_IDENTITY_BINARY); } stream.Close(); child = mime.CreateChildEntity(null); mimeHeader = child.CreateHeader("Content-Type"); mimeHeader.SetHeaderVal("multipart/related"); mimeHeader = child.CreateHeader("Content-Disposition"); mimeHeader.SetHeaderVal("attachment;filename=\"" + "Humidity.gif" + "\""); mimeHeader = child.CreateHeader("Content-ID"); mimeHeader.SetHeaderVal(sImage[1]); if (stream.Open(Directory.GetCurrentDirectory() + "[url=file://\\pic\\]\\pic\\[/url]" + sImage[1], "binary")) { if (stream.Bytes != 0) child.SetContentFromBytes(stream, "application/octet-stream" + "\"", MIME_ENCODING.ENC_IDENTITY_BINARY); } stream.Close(); child = mime.CreateChildEntity(null); mimeHeader = child.CreateHeader("Content-Type"); mimeHeader.SetHeaderVal("multipart/related"); mimeHeader = child.CreateHeader("Content-Disposition"); mimeHeader.SetHeaderVal("attachment;filename=\"" + "ExceptionInfo.xlsx" + "\""); mimeHeader = child.CreateHeader("Content-ID"); mimeHeader.SetHeaderVal(sImage[2]); if (stream.Open(Directory.GetCurrentDirectory() + "[url=file://\\excel\\]\\excel\\[/url]" + sImage[2], "binary")) { if (stream.Bytes != 0) child.SetContentFromBytes(stream, "application/octet-stream" + "\"", MIME_ENCODING.ENC_IDENTITY_BINARY); } stream.Close(); ns.ConvertMime = true; nDoc.SaveMessageOnSend = false; nDoc.ReplaceItemValue("postDate", DateTime.Now.ToShortDateString()); itemValue = nDoc.GetItemValue("SendTo"); nDoc.Send(false, ref itemValue); return true; } } catch (Exception error) { listBox1.Items.Add(error.Message + " Exception caughted " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); return false; } finally { ns = null; nd = null; nDoc = null; itemValue = null; GC.Collect(); } }
试试其它关键字
正文粘贴图片
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
sky3010
贡献的其它代码
(
1
)
.
如何在邮件正文粘贴图片
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3