Asp classic mail function sends string with blank

2019-08-10 01:45发布

问题:

I am sending a mail with CDO.Message object and the mail arrives with a blank space between characters.

For example, I sent this string:

"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

And arrives this:

"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in volup tate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

Check the strong word for understand. Why occurre that?

My code

        Set Mail= Server.CreateObject("CDO.Message")
        Set MailConfig = Server.CreateObject("CDO.Configuration")

        Mail.From = example@hotmail.com

        Mail.Bcc = "example@hotmail.com"

        Mail.Subject = "Example"  

        MailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = sendUsing
        MailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
        MailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smtpServerPort
        MailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        MailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = smtpUseSSL
        MailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = smtpConnectionTimeout
        MailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsername
        MailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword
        MailConfig.Fields.Update

        Mail.Configuration = MailConfig

        strBody = "the string"

        Mail.HTMLBody = strBody
        Mail.HTMLBodyPart.Charset = "utf-8"
        Mail.send

The extra space appears every 991 characters. I added this:

Mail.HTMLBodyPart.ContentTransferEncoding = "quoted-printable"

And has been solved.

回答1:

If you don't send HTML in the email body, do not make use of Mail.HTMLBody, instead use Mail.TextBody which is the correct choice when sending pure text. Textbody preserves line breaks and other control characters which HTMLBody does not.

I have experienced similar issues in Outlook when displaying raw text sent with HTMLBody, so I believe this simple change will fix it.