email adding extra spaces in text

nkotbox

Active member
Joined
May 28, 2011
Messages
31
Programming Experience
Beginner
I am using system.net.mail to create an html email and store to my drafts box in gmail (also using free S22.imap 4.0)
the email seems ok but I am getting extra white spaces in the body and cannot figure what I am doing wrong.
Is the odd HTML code causing issues ?
If I use the HTML visualizer in the code, the email seems fine.
Please see the code below and offer any suggestions as I am pulling whats left of my hair out

VB.NET:
Using Client As New ImapClient("imap.gmail.com", 993, EmailUser, YourPasswordTB.Text, AuthMethod.Login, True)
           
           Dim message As New System.Net.Mail.MailMessage()
            message.From = New MailAddress("myemail@here.com")
            message.[To].Add("youremail@here.com")
            
            message.IsBodyHtml = True
            message.Subject = EmailSub
            Dim strMsg


            ' below line is optional for high priority emails
            message.Priority = MailPriority.High


            ' company name w/red backround at top of email
            strMsg = ""
            strMsg = strMsg & "<html><body><p></p>"
            strMsg = strMsg & "<table width='100%' border='0' bgcolor='red'>"
            strMsg = strMsg & "<tr><td><h2><center><font size='5' color=black strong>Company Name</font></center></h2></td></tr>"
            strMsg = strMsg & "<tr><td><h3><center><font size='2' color=white>company modo</font></center></h3></td></tr>"
            strMsg = strMsg & "<tr></tr>"
            strMsg = strMsg & "</table></body></html>"
                      
            'Prepare email body
            EmailBody = strMsg & "<br>"
            EmailBody = EmailBody & "<br>"

            EmailBody = EmailBody & "Dear " & Customername.Text & ","
            EmailBody = EmailBody & "<br>"
            EmailBody = EmailBody & "<p>Thank you for choosing Company Name as a supplier of your new " & ModelCB.SelectedItem & ", S/N " & Serialnumber.Text & ". "
            EmailBody = EmailBody & "Before your machine arrives please take the time to review the attached Foundation print and Specification sheet"
            EmailBody = EmailBody & " that has the detailed information about your machine. Once you have reviewed this information click on the "
            EmailBody = EmailBody & link & " for more information in preparing the foundation and what should be done before your new Company Name " & ModelCB.SelectedItem & " arrives. </p>"
            EmailBody = EmailBody & "<p>Reviewing this information will allow for both, a smooth installation and demonstration.</p>"
            
            EmailBody = EmailBody & "<p>Should you have any questions preparing for the arrival of your new Company Name " & ModelCB.SelectedItem
            EmailBody = EmailBody & " or you are ready for your machine to be installed and demonstrated by your local Company Name "
            EmailBody = EmailBody & "Service Representative call any of the contacts listed below.</p>"
            
            EmailBody = EmailBody & "<p>We are looking forward to installing your new Company Name " & ModelCB.SelectedItem & ".</p>"
          
            EmailBody = EmailBody & "<p>Attachments: Foundation Print, Machine Specifications Sheet and " & link & "</p>"
         
            EmailBody = EmailBody & "<p>Respectfully,</p>"
           
                       EmailBody = EmailBody & "<FONT COLOR=8B0000 size='4' strong>Company Name</FONT>"
            EmailBody = EmailBody & "<br>Tom</br>"
         
            message.Body = EmailBody




        End Using
 
Is the odd HTML code causing issues ?
The html code is indeed bad, but the problem is with ImapClient I believe. I can confirm the spaces appearing everywhere in message after stored in Gmail, even with correct html body. When sending the message with Net.Mail.SmtpClient none of those appear.
The library doesn't appear to have any configuration that could change the result, but I discovered that if I created the message with alternate view instead of Body, then it was transmitted correctly, see How do I create a Multi-Part mime message? (the plain view wasn't necessary to add, I just used one html view).
 
spaces

The library doesn't appear to have any configuration that could change the result, but I discovered that if I created the message with alternate view instead of Body, then it was transmitted correctly, see How do I create a Multi-Part mime message? (the plain view wasn't necessary to add, I just used one html view).

I will try this method. Thanks for the suggestion.


...Worked perfectly, Thanks again.
 
Last edited:
Back
Top