vendredi 17 juin 2016

Remove random linebreak in html Email

I've had a problem for a few days now, and I simply can't explain why it happens. I'm currently working on sending an HTML email from Excel. Most of it works just fine, but I get these random line-breaks inside some paragraphs. This is my code VBA function:

Public Function EmailRapport(ByVal MailTo As String, UgeNr As String, ByVal Kunde As String, MailAtc As String)

Dim Mail As New Message
Dim Config As Configuration: Set Config = Mail.Configuration

Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "SMTPServer"
Config(cdoSMTPServerPort) = 25
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = "Email"
Config(cdoSendPassword) = "Password"
Config.Fields.Update

Mail.MimeFormatted = True

Mail.To = MailTo
Mail.Subject = "Subject"

Dim HTMLSource as string
HTMLSource = "<html>"
HTMLSource = HTMLSource & "<head>"
HTMLSource = HTMLSource & "<style> p {font-family: verdana; font-size: 14px; margin:0px; padding:0px;}</style>"
HTMLSource = HTMLSource & "</head>"
HTMLSource = HTMLSource & "<body style=""background-color:#EEEEEE; margin: 0px"">"
HTMLSource = HTMLSource & "<table style=""width:100%; max-width: 630px; min-width: 260px; margin: 0 auto; border-collapse: separate; border-spacing: 5px;""><tr><td><img src=""http://synsbasen.dk/images/synsbasen_logo_tekst.png"" height=""85px;""></td></tr>"
HTMLSource = HTMLSource & "<tr>"
HTMLSource = HTMLSource & "<td style=""background-color: white; padding: 15px; border:1px solid #e1e1e1; "">"
HTMLSource = HTMLSource & "<p>Hej " & Kunde & "</p><br>"
HTMLSource = HTMLSource & "<p>Synsbasen tilbyder nu et statistikværktøj udviklet til at hjælpe de individuelle synshaller. "
HTMLSource = HTMLSource & "Med Synsbasen får du nemt og overskueligt et overblik over din synsvirksomhed, samt mulighed for at "
HTMLSource = HTMLSource & "sammenligne dig på kryds og tværs med dine nærmeste konkurrenter.</p>"
HTMLSource = HTMLSource & "<br>"
HTMLSource = HTMLSource & "<p><b>Hvordan virker det?</b></p>"
HTMLSource = HTMLSource & "<p>Synsbasen indsamler alt tilgængeligt data vedrørende syn og køretøjer m.m., som indgår i vores ugentlige "
HTMLSource = HTMLSource & "rapporter. En rapport sammenligner som udgangspunkt sin egen virksomhed med 3 nærtliggende synshaller. "
HTMLSource = HTMLSource & "Vores rapporter er inddelt i 3 hovedkategorier.</p>"
HTMLSource = HTMLSource & "<br>"
HTMLSource = HTMLSource & "<p><b>Standard:</b></p>"
HTMLSource = HTMLSource & "<p>Standard rapporten indeholder antal syn for hver af de valgte synshaller og den tilsvarende markedsandel "
HTMLSource = HTMLSource & "som de hver i sær har, samt et kig på udviklingen af markedsandel over de seneste 13 uger. Antal syn og "
HTMLSource = HTMLSource & "markedsandel kan både ses på ugebasis, såvel som de individuelle dage i den aktuelle uge.</p>"
HTMLSource = HTMLSource & "<br>"
HTMLSource = HTMLSource & "<p><b>Udvidet:</b></p>"
HTMLSource = HTMLSource & "<p>Den udvidede rapport yderligere information om fordelingen af synsarter og synstyper, samt hvornår på "
HTMLSource = HTMLSource & "døgnet de enkelte syn er foretaget.</p>"
HTMLSource = HTMLSource & "<br>"
HTMLSource = HTMLSource & "<p><b>Individuel:</b></p>"
HTMLSource = HTMLSource & "<p>Ønskes yderligere statistik kan vi tilbyde en række tilkøb, herunder:<br>"
HTMLSource = HTMLSource & "• Fordelingen af køretøjernes km-stand<br>• Fordelingen af køretøjernes alder<br>"
HTMLSource = HTMLSource & "• Gennemsnits antal fejl / bil<br>"
HTMLSource = HTMLSource & "• Meddele hvornår de valgte synshaller har haft tilsyn af Trafikstyrelsen, og herunder om de er gået op eller ned i karakter.!</p>"
HTMLSource = HTMLSource & "<br>"
HTMLSource = HTMLSource & "<p>Fælles for alle kategorier er, at de udgives ugentligt for den forhenværende uge. Der er vedhæftet et eksempel på en standard "
HTMLSource = HTMLSource & "og en udvidet rapport. Har jeres synsvirksomhed nogle specielle ønsker eller forslag, er du meget velkommen til at kontakte mig.</p>"
HTMLSource = HTMLSource & "<br>"
HTMLSource = HTMLSource & "<p><b>Hvad koster det?</b></p>"
HTMLSource = HTMLSource & "<p>Du tegner et løbende abonnement på 6 mdr. af gangen.<br>"
HTMLSource = HTMLSource & "Standard Rapport:  2.500 kr. / 6 mdr. (eks. moms.)<br>"
HTMLSource = HTMLSource & "Udvidet Rapport: 3.500 kr. / 6 mdr. (eks. moms.)<br>"
HTMLSource = HTMLSource & "Oprettelsesgebyr: 1.000 kr. (eks. moms.)<br>"
HTMLSource = HTMLSource & "Ændringer i valgte synshaller m.m.: 500 kr. (eks. moms.)</p>"
HTMLSource = HTMLSource & "<br>"
HTMLSource = HTMLSource & "<p>Har du spørgsmål eller kommentarer er du alti velkommen til at kontakte mig på info@synsbasen.dk eller tlf. 30 202 606. "
HTMLSource = HTMLSource & "Jeg kontakter dig en gang i næste uge, hvis ikke jeg hører fra dig inden.</p>"
HTMLSource = HTMLSource & "<br>"
HTMLSource = HTMLSource & "<p>Med venlig hilsen<br>Tobias Knudsen</p>"
HTMLSource = HTMLSource & "</td>"
HTMLSource = HTMLSource & "</tr>"
HTMLSource = HTMLSource & " <tr><td><p style=""text-align: center; font-family: verdana; font-size: 12px; margin:0px; padding:0px;""> Synsbasen</p></td></tr></table></body></html>"

Mail.HTMLBody = HTMLSourceOn Error Resume Next
Mail.Send
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "There was an error"
Exit Function
Else
End If
End Function

Here you see a picture from the mail I receive. The word 'Forhenværende' should not be split with a space and it's clearly spelled in one word in the VBA code.

enter image description here

I couldn't find the extra space in my VBA-code so I checked the HTML code from the email. Here I found something interesting. It adds a linebreak in as shown in the picture below:

Picture of HTML code from Email

When I save the HTML Source code as a .html file and open it in my browser it displays the mail as it should. Have anyone of you ever ran into a similar problem?

Aucun commentaire:

Enregistrer un commentaire