-
Jan 19th, 2021, 11:32 PM
#1
Thread Starter
Hyperactive Member
I'm missing the text in my Mail.Body email.
Hello!
I'm trying to send an email from a windows form application using VB.NET. the email contains some text and an embedded image. I get to send the image, but the text is totally missing, my Mail.Body comes from a TextBox in this case is the TextBox6.Text
This is my code so far.
vb.net Code:
Dim Mail As New MailMessage
Mail.From = New MailAddress("sistemadecontrolmorelia@gmail.com", TextBox7.Text)
Mail.[To].Add(New MailAddress(Enviar_a_Correo))
Mail.Subject = TextBox7.Text
Dim img1 As LinkedResource = New LinkedResource("C:\Users\dante\Downloads\Black_Hole.jpg", MediaTypeNames.Image.Jpeg)
img1.ContentId = "Image1"
Mail.Body = Mail.Body & "<td><img src=cid:Image1 alt=></td>"
Dim av1 As AlternateView = AlternateView.CreateAlternateViewFromString(Mail.Body, Nothing, MediaTypeNames.Text.Html)
av1.LinkedResources.Add(img1)
Mail.AlternateViews.Add(av1)
Mail.IsBodyHtml = True
Mail.Body = TextBox6.Text
Using SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New Net.NetworkCredential("myMail@gmail.com", "myPassword")
SMTP.Port = "587"
SMTP.Send(Mail)
End Using
This is what the mail looks like.
-
Jan 20th, 2021, 12:54 PM
#2
Re: I'm missing the text in my Mail.Body email.
That's because you didn't include it in your view. The email you've created contains two bodies as you've defined it. A text (which is the default) and an HTML view (defined by the alternate view) which is used by clients that support it (such as the web client you're using). But the text from the text box wasn't set until after you create the alternate view, so it wasn't included. If you want it included, you need to build up the HTML first, then use it when creating the alternate view for hte HTML view of the email ...
-tg
-
Jan 20th, 2021, 07:37 PM
#3
Thread Starter
Hyperactive Member
Re: I'm missing the text in my Mail.Body email.
Hi techgnome, Your're right I implemented the fix you suggested and it worked just fine.
Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|