如何使用gmail在电子邮件中发送图像而不是附件 [英] How to I send the image in email and not as attachment using gmail

查看:216
本文介绍了如何使用gmail在电子邮件中发送图像而不是附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'wt code in this codes?

'wt wrong in this codes ?

Imports System.Net.Mail
Imports System.Net.Mime
Imports System.IO
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New Net.NetworkCredential("Accountname","yourpassword")
            Smtp_Server.Port = 587
            Smtp_Server.EnableSsl = True
            Smtp_Server.Host = "smtp.gmail.com"
            e_mail = New MailMessage()
            e_mail.From = New MailAddress("yourname@gmail.com") 'self emaling 
            e_mail.To.Add("yourname@gmail.com")' self email 
            e_mail.Subject = "Email Sending with image"
            'the current folder of the compiled file has a image named 1.jpg
            Dim path As String = "1.jpg"
            Dim imageLink As New LinkedResource(path)
            imageLink.ContentId = "myImage"
            Dim altView As AlternateView = AlternateView.CreateAlternateViewFromString("<html><body><img src=cid:myImage/>" + "<br></body></html>", Nothing, MediaTypeNames.Text.Html)
            altView.LinkedResources.Add(imageLink)
            e_mail.AlternateViews.Add(altView)
            e_mail.IsBodyHtml = True
            e_mail.Body = ""
            Smtp_Server.Send(e_mail)
            MsgBox("Mail Sent")
        Catch error_t As Exception
            MsgBox(error_t.ToString)
        End Try
    End Sub
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Me.Text = "this email was test by vimal singh "
    End Sub
End Class</br>

推荐答案

在电子邮件中,您可以简单地嵌入一个可以保存图像的图像元素。只需确保您传递的链接正确无误。大多数情况下,还需要HTTP或HTTPS协议,因为您的服务器上存在的图像文件不是他们的。像这样,



In email, you can simply embed an image element which would hold the image. Just make sure that the link you pass is correct. Mostly, HTTP or HTTPS protocol would also be required, because the image file exists on your server not theirs. Like this,

"<html>
  <body>
    <img src="http://www.example.com/images/file.png" alt="image-name" />
  </body>
</html>"





生成HTML电子邮件的一些有用帖子包括:

http://webdesign.tutsplus.com/articles/creating-a-simple-responsive-html-email--webdesign-12978 [ ^ ]

http://stackoverflow.com / questions / 886728 / generating-html-email-body-in-c-sharp [ ^ ]

HTTP://www.creativ ebloq.com/netmag/how-create-great-looking-responsive-html-emails-81412552 [ ^ ]



简单的HTML文档作为电子邮件正文,电子邮件客户端会在屏幕上呈现。



A few helpful posts for generating HTML emails include:
http://webdesign.tutsplus.com/articles/creating-a-simple-responsive-html-email--webdesign-12978[^]
http://stackoverflow.com/questions/886728/generating-html-email-body-in-c-sharp[^]
http://www.creativebloq.com/netmag/how-create-great-looking-responsive-html-emails-81412552[^]

Simple HTML document is sent as the email body, and email client would render that on screen.



我想你尝试使用你的链接发送图片,在你的链接路径需要提供正确的服务器路径,只是1.png不起作用。
Hi I think u r try to send image using ur link,in ur link Path need to give correct server path ,simply 1.png not work.


这篇关于如何使用gmail在电子邮件中发送图像而不是附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆