Foxtable(狐表)用户栏目专家坐堂 → 请教老师, 怎么发送内容带有图片的邮件


  共有2345人关注过本帖树形打印复制链接

主题:请教老师, 怎么发送内容带有图片的邮件

帅哥哟,离线,有人找我吗?
rayfux3322
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:61 积分:633 威望:0 精华:0 注册:2019/7/19 12:38:00
请教老师, 怎么发送内容带有图片的邮件  发帖心情 Post By:2019/8/29 17:05:00 [只看该作者]

如题, 谢谢

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107023 积分:544346 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/8/29 17:06:00 [只看该作者]

参考:

Dim client As New System.Net.Mail.SmtpClient()
client.Host = "smtp.qq.com"
client.Credentials = New System.Net.NetworkCredential("455189993@qq.com", "helen6849338.")
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Dim message As New System.Net.Mail.MailMessage
message.From = new System.Net.Mail.MailAddress("455189993@qq.com")
message.To.Add("2450314695@qq.com")
message.Subject = "主题测试"
message.BodyEncoding = System.Text.Encoding.UTF8
message.IsBodyHtml = True

Dim attach1 As new System.Net.Mail.Attachment("D:\a.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg);
attach1.C '设置ContentId

Dim body As String = "<html><body>内容</body></html>"
Dim content As String = "12345678<font size=7 color=red>12345678</font><img src=""cid:pic1""/><p>来自张三.</p>"

message.Body = body.Replace("内容", content)

Try
    client.Send(message)
    msgbox("发送成功")
Catch ex As Exception
    msgbox("发送失败:" & ex.message)
End Try

 回到顶部
帅哥哟,离线,有人找我吗?
rayfux3322
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:61 积分:633 威望:0 精华:0 注册:2019/7/19 12:38:00
  发帖心情 Post By:2019/8/29 17:57:00 [只看该作者]

"12345678<font size=7 color=red>12345678</font><img src=""cid:pic1""/><p>来自张三.</p>"

这部分是不是直接替换成 内容的HTML格式内容?

 回到顶部
帅哥哟,离线,有人找我吗?
rayfux3322
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:61 积分:633 威望:0 精华:0 注册:2019/7/19 12:38:00
  发帖心情 Post By:2019/8/29 18:02:00 [只看该作者]

我现在是把正文内容(带图片)的写在WORD里,然后上网把它转成了HTML格式, 是不是把这个文件的源代码全部考到上面的""里, 图片地址改一下就OK?
我试了下, 源代码很长,老报错, 还有这句也报错,Dim attach1 As new System.Net.Mail.Attachment("D:\a.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg);
attach1.C '设置ContentId

 回到顶部
帅哥,在线噢!
有点蓝
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107023 积分:544346 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/8/30 10:58:00 [只看该作者]

Dim content As String = "其它正文内容<img src=""cid:pic1""/>其它正文内容"

 回到顶部
帅哥哟,离线,有人找我吗?
rayfux3322
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:61 积分:633 威望:0 精华:0 注册:2019/7/19 12:38:00
  发帖心情 Post By:2019/8/30 13:29:00 [只看该作者]

系统提示:
---------------------------
编译错误:“C”不是“System.Net.Mail.Attachment”的成员。



错误代码:attach1.C '设置ContentId
---------------------------
确定   
---------------------------


这个要调哪里

 回到顶部
帅哥,在线噢!
有点蓝
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107023 积分:544346 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/8/30 14:43:00 [只看该作者]

代码被浏览器屏蔽了

Dim attach1 As new System.Net.Mail.Attachment("D:\a.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg);
attach1.ContentId ="pic1" '设置ContentId

 回到顶部
帅哥哟,离线,有人找我吗?
rayfux3322
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:61 积分:633 威望:0 精华:0 注册:2019/7/19 12:38:00
  发帖心情 Post By:2019/8/30 15:25:00 [只看该作者]

不好意思,上面这段搞懂了, 上面只是内容很少的情况下我试了是成功的, 不过,邮件如果内容很多的话,怎么办, 还有很多转行之类的, 都不知怎么来写, 比如下面的HTML内容, 怎么办,

<div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" bgcolor="#ff5c4c" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0" width="600"><tbody><tr><td height="40">&nbsp;</td></tr><tr><td align="center" data-link-color="Header Link" data-link-style="text-decoration:none; color:#21b6ae;" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, Arial, sans-serif; font-size:22px; color:#FFFFFF;">- 2018 -</td></tr><tr><td height="20">&nbsp;</td></tr><tr><td align="center" data-link-color="Header Link" data-link-style="text-decoration:none; color:#21b6ae;" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, Arial, sans-serif; font-size:50px;line-height: 66px; color:#FFFFFF;font-weight: bold;">最简单的邮件<br />Newsletter定制平台</td></tr><tr><td height="35">&nbsp;</td></tr><tr><td height="30">&nbsp;</td></tr><tr><td align="center" data-link-color="Header Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Header Slogan" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, Arial, sans-serif; font-size: 24px; color: rgb(255, 255, 255); line-height: 36px;">肯为旎邮件DIY | 2018.01.01</td></tr><tr><td height="50">&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div><div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" bgcolor="#ffffff" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0" width="600"><tbody><tr><td height="40">&nbsp;</td></tr><tr><td align="center" data-color="Main Color" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Headlines" style="font-family:'Microsoft YaHei',微软雅黑,'Microsoft JhengHei'; font-size: 25px; font-weight: bold; color: rgb(255, 92, 76); line-height: 42.5px;">如何更换文字</td></tr><tr><td height="10">&nbsp;</td></tr><tr><td align="left" data-color="Main Text" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Main Text" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, 微软雅黑, 'Microsoft JhengHei'; font-size: 16px; line-height: 22.5px; color: rgb(81, 81, 81);"><p>移动鼠标到需要更换(或者添加)文字的地方,拖拽鼠标来选中文字(或点击鼠标定位),输入文字即可,完成更换。换一句话,就是说将原来模板中的文字更换成自己的文字内容,就这么简单。本来想多说两句,描述得更清楚点,但确实没有什么可说的了,简单粗暴,哈哈。</p><p>&nbsp;</p></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div><div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" bgcolor="#ECF0F1" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0" width="600"><tbody><tr><td height="20" style="font-size: 0;line-height: 0;border-collapse: collapse;">&nbsp;</td></tr><tr><td><table align="left" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" style="border:2px solid #ffffff;"><img height="210" src="http://diy.kenweini.com/sites/default/files/zhongguoguan.jpg" style="display: block; line-height: 0px; font-size: 0px; border: 0px none;" width="220" /></td><td align="center" style="line-height:0px;" valign="middle" width="30">&nbsp;</td><td align="left" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑,微软雅黑,'Microsoft JhengHei'; font-size: 15px; color: rgb(50, 50, 50); line-height: 22.5px;" valign="top"><p style="font-family:'Microsoft YaHei',微软雅黑,'Microsoft JhengHei'; font-size: 25px; font-weight: bold;  line-height: 42.5px;">如何更换图片</p>① 鼠标双击左侧的图片,打开图片属性。<br />② 更换URL地址为自己图片的网络地址。<br />③ 最后点击确定,更换完成。<p>另外,还可在图片属性中添加“替换文本”、设置合适的宽度和高度、设置对齐方式、添加链接和新窗口打开等。</p></td></tr></tbody></table></td></tr><tr><td height="20">&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div><div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" bgcolor="#ffffff" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0" width="600"><tbody><tr><td height="40">&nbsp;</td></tr><tr><td align="center" data-color="Main Color" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Headlines" style="font-family:'Microsoft YaHei',微软雅黑,'Microsoft JhengHei'; font-size: 25px; font-weight: bold; color: rgb(255, 92, 76); line-height: 42.5px;">如何更换文字颜色</td></tr><tr><td height="10">&nbsp;</td></tr><tr><td align="left" data-color="Main Text" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Main Text" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, 微软雅黑, 'Microsoft JhengHei'; font-size: 16px; line-height: 22.5px; color: rgb(81, 81, 81);"><p>第一步,请先选中要更换颜色的文字; 第二步,然后在颜色区选中“文本颜色 Text color”或“文本背景色 Text background ”;第三步,点击取色器的彩色圆环部分来选取一个颜色区,再在取色器的彩色方块部分按住鼠标并拖动,文字颜色会随鼠标的拖动而动态改变。</p><p>&nbsp;</p></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div><div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" bgcolor="#ECF0F1" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0" width="600"><tbody><tr><td height="40">&nbsp;</td></tr><tr><td align="center" data-color="Main Color" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Headlines" style="font-family:'Microsoft YaHei',微软雅黑,'Microsoft JhengHei'; font-size: 25px; font-weight: bold; color: rgb(255, 92, 76); line-height: 42.5px;">无须编程知识</td></tr><tr><td height="10">&nbsp;</td></tr><tr><td align="center" style="color:#333; font-size: 18px; font-family: '微软雅黑';"><p style="color: #F65B24;font-size: 18px; font-family: '微软雅黑'; font-weight:bold;">只需要简单的编辑、更换等操作</p><p style="color: #E27C14;font-size: 18px; font-family: '微软雅黑'; font-weight:bold;">就可以自行定制出专业级别的图文邮件</p></td></tr><tr><td height="40">&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div><div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" bgcolor="#ffffff" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0" width="600"><tbody><tr><td height="40">&nbsp;</td></tr><tr><td align="center" data-color="Main Color" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Headlines" style="font-family:'Microsoft YaHei',微软雅黑,'Microsoft JhengHei'; font-size: 25px; font-weight: bold; color: rgb(255, 92, 76); line-height: 42.5px;">如何更换区块颜色</td></tr><tr><td height="10">&nbsp;</td></tr><tr><td align="left" data-color="Main Text" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Main Text" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, 微软雅黑, 'Microsoft JhengHei'; font-size: 16px; line-height: 22.5px; color: rgb(81, 81, 81);"><p>第一步,请先选中某个区块的手柄(选中时手掌会变为拳头); 第二步,然后在颜色区选中“区块背景色 Block background ”或“内容区背景 Content background ”;第三步,点击取色器的彩色圆环部分来选取一个颜色区,再在取色器的彩色方块部分按住鼠标并拖动,区块背景色会随鼠标的拖动而动态改变。</p></td></tr><tr><td height="10">&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div><div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td height="30">&nbsp;</td></tr><tr><td align="center" style="font-size: 14px; font-family:'Microsoft Yahei',Helvetica,verdana, Arial;color:#ffffff;text-align:center;padding-top:15px;font-size:18px;border-radius: 30px;background-color: #FF5C4C;padding: 12px;font-weight: bolder;"><a data-color="Button Link" href="http://diy.kenweini.com" style="color:#ffffff;text-decoration:none;" target="_blank">点我直达“肯为旎”,等您查看</a></td></tr><tr><td height="16">&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div><div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" bgcolor="#ffffff" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0" width="600"><tbody><tr><td height="16">&nbsp;</td></tr><tr><td align="left" data-color="Main Text" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Main Text" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, 微软雅黑, 'Microsoft JhengHei'; font-size: 16px; line-height: 22.5px; color: rgb(81, 81, 81);"><p>如何修改链接?双击上面的链接打开属性,更换链接地址(URL)为自己的,最后点击确定即可。</p></td></tr><tr><td height="10">&nbsp;</td></tr><tr><td align="left" data-color="Main Text" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Main Text" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, 微软雅黑, 'Microsoft JhengHei'; font-size: 16px; line-height: 22.5px; color: rgb(81, 81, 81);"><p>本平台还有更多更强大的功能等您来体验,比如格式刷和样式设置功能,可以帮助您大大提高工作效率,再也无须繁琐的重复操作了,详情请登录网站,查看帮助。</p></td></tr><tr><td height="36">&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div><div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" bgcolor="#E2E6E7" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0" width="600"><tbody><tr><td height="20">&nbsp;</td></tr><tr><td><table align="left" border="0" cellpadding="0" cellspacing="0" width="190"><tbody><tr><td data-color="Headlines" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Headlines" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, Arial, sans-serif; font-size: 20px; color: rgb(59, 59, 59); line-height: 34px; font-weight: bold;">肯为旎-DIY</td></tr><tr><td height="16">&nbsp;</td></tr><tr><td><table align="right" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td style="line-height:0px;" width="15"><img data-crop="false" height="17" src="http://diy.kenweini.com/sites/default/files/heart64.png" style="display:block; line-height:0px; font-size:0px; border:0px;" width="17" /></td><td width="10">&nbsp;</td><td align="left" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, Arial, sans-serif; font-size:15px; color:#7f8c8d; line-height:26px;">400 800 0001</td></tr></tbody></table></td></tr><tr><td height="5">&nbsp;</td></tr><tr><td><table align="right" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td style="line-height:0px;" width="15"><img data-crop="false" height="17" src="http://diy.kenweini.com/sites/default/files/heart64.png" style="display:block; line-height:0px; font-size:0px; border:0px;" width="17" /></td><td width="10">&nbsp;</td><td align="left" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, Arial, sans-serif; font-size:13px; color:#7f8c8d; line-height:26px;"><a data-color="Content Link" style="color: rgb(127, 140, 141); text-decoration: none;">mail@163.com</a></td></tr></tbody></table></td></tr></tbody></table></td><td width="30">&nbsp;</td><td><table align="right" border="0" cellpadding="0" cellspacing="0" width="330"><tbody><tr><td data-color="Headlines" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Headlines" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, Arial, sans-serif; font-size: 20px; color: rgb(59, 59, 59); line-height: 34px; font-weight: bold;">联系我们</td></tr><tr><td height="16">&nbsp;</td></tr><tr><td data-color="Main Text" data-link-color="Content Link" data-link-style="text-decoration:none; color:#21b6ae;" data-size="Main Text" style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑,微软雅黑,'Microsoft JhengHei'; font-size: 15px; color: rgb(60, 95, 98); line-height: 25.5px; text-align: left;">电话: &nbsp;000 - 1234 5678<br /><span><i><span style="font-style: normal;">传真: &nbsp;000 - 1234 5678</span></i><br />地</span> <span>址:</span> 上海市静安区南京路000号大地广场A座18</td></tr></tbody></table></td></tr><tr><td height="20">&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div><div><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td align="center" bgcolor="#c2d0d4" valign="top"><table align="center" border="0" cellpadding="0" cellspacing="0" width="650"><tbody><tr><td><table align="center" border="0" cellpadding="0" cellspacing="0" width="600"><tbody><tr><td height="40">&nbsp;</td></tr><tr><td><table align="left" border="0" cellpadding="0" cellspacing="0" height="0" width="100%"><tbody><tr><td style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑,微软雅黑,'Microsoft JhengHei'; font-size: 17px; color: rgb(60, 95, 98); line-height: 25.5px;" valign="middle"><a data-color="Content Link" href="http://www.baidu.com" style="text-decoration: none; color: rgb(255, 92, 76);font-weight: bold;" target="_blank">肯为旎网络科技有限公司</a></td><td style="font-family: 'Microsoft Yahei', 'Microsoft JhengHei', 微软雅黑, Arial, sans-serif; font-size:15px; color:rgb(255, 92, 76); line-height:29px;font-weight: bold;"><a href="http://www.baidu.com" style="text-decoration: none; color: rgb(255, 92, 76);font-weight: bold;" target="_blank">www.kenweini.com</a></td></tr></tbody></table></td></tr><tr><td height="40">&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div>

 回到顶部
帅哥,在线噢!
有点蓝
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107023 积分:544346 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/8/30 15:29:00 [只看该作者]

Dim content As String = "其它任意html代码<div>.........</div>其它正文内容"

 回到顶部
帅哥哟,离线,有人找我吗?
rayfux3322
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:61 积分:633 威望:0 精华:0 注册:2019/7/19 12:38:00
  发帖心情 Post By:2019/8/30 15:51:00 [只看该作者]

其它任意html代码要在代码编辑器里要转行怎么办呢,

 回到顶部
总数 23 1 2 3 下一页