locked
Using CDO.Message with CreateMHTMLBody RRS feed

  • Question

  • Hello, we have a classic ASP application which is being tested on Azure before full migration.

    Everything is fine except sending email with .CreateMHTMLBody:

    - Using a http or https path to the email template file we want to use, simply times out and no email is sent. Example:

    objMsg.CreateMHTMLBody "https://www.oursite.net/EMAIL_TEMPLATES/Template1.asp?FNAME=XXX"

    - If we use a physical path and a non asp file to send it all works fine, e.g:

    D:\home\site\wwwroot\CM\INCLUDES\FUNCTIONS\<FILENAME>.htm.

    So my question is how to I get .CreateMHTMLBody working with a URL or relative file path and an asp file?

    Thank you

    Chris

    Friday, June 23, 2017 1:08 PM

All replies

  • There are several ways to send emails from an Azure App Server (Web App) for example using SendGrid from the marketplace or sending an email using your O365 SMTP server.

    A point to consider when sending emails from an App Service is that if you send spam or to many emails, then the IP address of your App will be blacklisted, and it will shut down your App.  So, do not use an Azure Web App to send spam or bulk emails.

    I suggest you take a look into the suggestions outlined by Benjamin Perkins in this Azure App Services - Send an Email and see if it helps.

    You may wish to check Azure App Service Migration Assistant – It is a tool that moves your web sites from your web servers to the Microsoft Azure Cloud.

    Refer to the article File structure on azure to know the sets of files & dirs on Azure WebApp for more details.

    ---------------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    Saturday, June 24, 2017 12:11 PM
    Owner
  • Hello Ajay, thanks for your reply.

    I use SendGrid. Sending a flat html file works fine. It's sending an .asp file as the email body that times out on Azure.

    We have no issue sending from our current Windows 2012 server, same code base etc.

    I can't find any information on why Azure is preventing us using CDO.Message with CreateMHTMLBody with a URL and asp file. I have checked through the App logs but we only get a time out message - not what is causing the timeout.

    Are there any security settings preventing using asp files in the mail body?

    Chris

    Monday, June 26, 2017 8:39 AM
  • I suggest that you enable FREB on your site to analyze the failing request. Alternatively, you could try to repro the issue with the following example, assuming you have relay permissions to send the email to a valid smtp server:

    <% Set myMail = CreateObject("CDO.Message") myMail.Subject = "Sending email with CDO" myMail.From = "mymail@mydomain.com" myMail.To = "someone@somedomain.com" myMail.TextBody = "This is a message."

    myMail.CreateMHTMLBody = "https://<some-antares-site>.azurewebsites.net/email-content.asp"

    myMail.Send %>

    Monday, June 26, 2017 6:31 PM
  • Hello Donna, thanks for your reply.

    As per your note and for ease of debugging I created a simple mail sending script as above and enabled FREB. This is the outcome:

    IF sending a .HTM file with a FilePath ("D:\home\site\wwwroot\EMAIL_TEMPLATES\EXIT\test.htm)  THE EMAIL IS SENT.

    IF sending a .ASP file with a FilePath ("D:\home\site\wwwroot\EMAIL_TEMPLATES\EXIT\test.asp)  THE EMAIL NOT SENT and errors with "The content type was not valid in this context. For example, the root of an MHTML message must be an HTML document."

    (please note that both test.htm and test.asp are the same file)


    IF .HTM file and URL (http://gwtcm.azurewebsites.net/EMAIL_TEMPLATES/EXIT/test.htm) - TIME OUT, NOT SENT, ERROR 500

    IF .ASP file and URL (http://gwtcm.azurewebsites.net/EMAIL_TEMPLATES/EXIT/test.asp) - TIME OUT, NOT SENT, ERROR 500

    You can view both test.asp and test.htm in your browser and the paths are correct.

    When I view the detailed errors I get:

    <failedRequest url="http://GWTCM:80/TMP/CDO.asp"
                   siteId="1528990715"
                   appPoolId="GWTCM"
                   processId="10684"
                   verb="GET"
                   remoteUserName=""
                   userName=""
                   tokenUserName="IIS APPPOOL\GWTCM"
                   authenticationType="anonymous"
                   activityId="{00000000-0000-0000-BB0A-0080000000E2}"
                   failureReason="STATUS_CODE"
                   statusCode="500"
                   triggerStatusCode="500"
                   timeTaken="31"
                   xmlns:freb="http://schemas.microsoft.com/win/2006/06/iis/freb"
    >

    Which doesn't tell me a lot more than the 500 I get in the browser.

    So I still have no idea why .CreateMHTMLBody is not working with an asp file, a full path with GET.

    Is there some kind of permission issue here? I've read about XDT transformations so I am not sure if need additional configuration or there is something intrinsically wrong with my web app instance on Azure.

    Thanks

    Chris


    • Edited by GWTAzure Tuesday, June 27, 2017 3:43 PM
    Tuesday, June 27, 2017 3:42 PM
  • Can anyone help?

    Monday, July 17, 2017 10:14 AM
  • Hello, we have a classic ASP application which is being tested on Azure before full migration.

    Everything is fine except sending email with .CreateMHTMLBody:

    - Using a http or https path to the email template file we want to use, simply times out and no email is sent. Example:

    objMsg.CreateMHTMLBody "https://www.oursite.net/EMAIL_TEMPLATES/Template1.asp?FNAME=XXX"

    - If we use a physical path and a non asp file to send it all works fine, e.g:

    D:\home\site\wwwroot\CM\INCLUDES\FUNCTIONS\<FILENAME>.htm.

    So my question is how to I get .CreateMHTMLBody working with a URL or relative file path and an asp file?

    Thank you

    Chris

    Quite late on this, but since it surfaced elsewhere, lately, I decided to post here too in the hope this may help others.

    When using CreateMHTMLBody with files, you must turn the file pathname into a regular file type URL, this means that if the file you want to use is "D:\home\site\wwwroot\CM\INCLUDES\FUNCTIONS\foobar.htm" the URL passed to CreateMHTMLBody will be "file://D:/home/site/wwwroot/CM/INCLUDES/FUNCTIONS/foobar.htm"

    Notice that any file pathname contained inside the HTML file will also need to use the same format as above

    Example

    <HTML>
     <HEAD>
      <TITLE>Example</TITLE>
     </HEAD>
     </BODY>
      <DIV>
        <IMG SRC="file://D:/some/path/image.jpg">
      </DIV>
     </BODY>
    </HTML>

    otherwise the CreateMHTMLBody won't be able to load external files and convert them to embedded resources

    HTH

    Edit:

    Forgot to add an important information; if the file pathname contains spaces or "special" chars, those must be "URL encoded", that is spaces must be converted to %20 and so on, otherwise, even using the correct URL format (file://...) for the file pathname, the CreateMHTMLBody method will fail to work


    Monday, January 22, 2018 11:55 AM
  • Thank you for posting the solution that helped you.

    ---------------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    Tuesday, January 23, 2018 7:54 PM
    Owner