本文介绍了如何使用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("[email protected]") 'self emaling 
            e_mail.To.Add("[email protected]")' 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>

推荐答案

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





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

[]

[]

[]



简单的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.



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

08-27 05:14