简体   繁体   中英

vb.net send email with image

there is a lot of topic about sending email with attachment but i couldn't find what i was looking for my form contain 8 textbox and 1 PictureBox i can send all textbox via email but ican't send PictureBox i try many code

this is my form .

and here is my code

    Dim MyMessage As New MailMessage
    Try
        MyMessage.From = New MailAddress("x@gmail.com")

        MyMessage.To.Add("x@gmail.com")

        MyMessage.Subject = "Data"

        MyMessage.Body = Label1.Text + "  =  " + IDTextBox.Text + Environment.NewLine + Label2.Text + "  =  " + ناوی_سیانی_کارمەندTextBox.Text + Environment.NewLine + Label3.Text + "  =  " + ساڵی_لە__دایک_بوونTextBox.Text + Environment.NewLine + Label4.Text + "  =  " + شوێنی_دانیشتنTextBox.Text + Environment.NewLine + Label5.Text + "  =  " + گروپی_خوێنTextBox.Text + Environment.NewLine + Label6.Text + "  =  " + ناو_نیشانی_کار_لە_کۆمپانیاTextBox.Text + Environment.NewLine + Label7.Text + "  =  " + ژمارەی_مۆبایلTextBox.Text + Environment.NewLine + Label8.Text + "  =  " + شوێنی_کارTextBox.Text

        Dim SMTP As New SmtpClient("smtp.gmail.com")
        SMTP.Port = 587
        SMTP.EnableSsl = True
        SMTP.Credentials = New System.Net.NetworkCredential("x@gmail.com", "x")
        SMTP.Send(MyMessage)
        MsgBox("your message Has been sent successfully")
    Catch ex As Exception

    End Try

i will be greatfull if you could help me :)

Have you tried this.You can use the LinkedResource and AlternatiView for the same.

string path = Filelocation; // as you are using picture box,give the location from where the image is loading into picture box. 

LinkedResource imageLink = new LinkedResource(path);
imageLink.ContentId = "myImage";
AlternateView altView = AlternateView.CreateAlternateViewFromString(
  "<html><body><img src=cid:myImage/>" + 
  "<br></body></html>" + strMailContent, 
  null, MediaTypeNames.Text.Html);
altView.LinkedResources.Add(imageLink);

//now append it to the body of the mail
msg.AlternateViews.Add(altView);
msg.IsBodyHtml = true;

or You can send it with HtmlBody here is the reference : http://vba-useful.blogspot.fr/2014/01/send-html-email-with-embedded-images.html

You need to add the directory of the picture file or any file you have and add it as attachment to your mail like this...

Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment(FilePath)
MyMessage.Attachments.Add(attachment)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM