Results 1 to 3 of 3

Thread: I'm missing the text in my Mail.Body email.

  1. #1

    Thread Starter
    Hyperactive Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    256

    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:
    1. Dim Mail As New MailMessage
    2. Mail.From = New MailAddress("sistemadecontrolmorelia@gmail.com", TextBox7.Text)
    3. Mail.[To].Add(New MailAddress(Enviar_a_Correo))
    4. Mail.Subject = TextBox7.Text
    5.  
    6. Dim img1 As LinkedResource = New LinkedResource("C:\Users\dante\Downloads\Black_Hole.jpg", MediaTypeNames.Image.Jpeg)
    7. img1.ContentId = "Image1"
    8. Mail.Body = Mail.Body & "<td><img src=cid:Image1 alt=></td>"
    9. Dim av1 As AlternateView = AlternateView.CreateAlternateViewFromString(Mail.Body, Nothing, MediaTypeNames.Text.Html)
    10. av1.LinkedResources.Add(img1)
    11. Mail.AlternateViews.Add(av1)
    12. Mail.IsBodyHtml = True
    13. Mail.Body = TextBox6.Text
    14.  
    15. Using SMTP As New SmtpClient("smtp.gmail.com")
    16.          SMTP.EnableSsl = True
    17.          SMTP.Credentials = New Net.NetworkCredential("myMail@gmail.com", "myPassword")
    18.          SMTP.Port = "587"
    19.          SMTP.Send(Mail)
    20. End Using

    This is what the mail looks like.
    Name:  Captura de pantalla 2021-01-19 221737.jpg
Views: 182
Size:  33.8 KB

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,213

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    256

    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
  •  



Click Here to Expand Forum to Full Width