sending mail in html format thru Stored Procedure

  • hi friends,

    i am sending a mail thru CDonts via Stored Procedure. The mail is scheduled by job. The mail is sent using sp_OAMethod. The mail is going but i want it in good html format but i am not able to include html format. How can i do it. the code is as follows:

    to VARCHAR(8000),

    @subject VARCHAR(8000),

    @body VARCHAR(8000)

    AS

    DECLARE @result INT

    DECLARE @object INT

    PRINT 'Creating the CDONTS.NewMail object'

    EXEC @result = sp_OACreate 'CDONTS.NewMail', @object OUTPUT

    IF @result <> 0

    BEGIN

    PRINT 'sp_OACreate Failed'

    RETURN @result

    END

    PRINT 'Sending the message using the Send method'

    EXEC @result = sp_OAMethod @object, 'Send', NULL, @from, @to, @subject, @body

    IF @result <> 0

    BEGIN

    PRINT 'sp_OAMethod Failed'

    RETURN @result

    END

    PRINT 'Destroying the CDONTS.NewMail object'

    EXEC @result = sp_OADestroy @object

    IF @result <> 0

    BEGIN

    PRINT 'sp_OADestroy Failed'

    RETURN @result

    END

    RETURN 0

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

    Please suggest the needed.

    Regards,

    sunayana


    sunayana

  • Pulled this from msdn:

    Example

    This code fragment shows the usage of the BodyFormat property in preparing and sending an HTML message:

    Dim myMail

    Set myMail = CreateObject("CDONTS.NewMail")

    HTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & vbCrLf

    HTML = HTML & "<html>"

    HTML = HTML & "<head>"

    HTML = HTML & "<meta http-equiv=""Content-Type"""

    HTML = HTML & ""content=""text/html; charset=iso-8859-1"">""

    HTML = HTML & "<title>Sample NewMail</title>"

    HTML = HTML & "</head>"

    HTML = HTML & "<body>"

    HTML = HTML & "This is a sample message being sent using HTML. <BR></body>"

    HTML = HTML & "</html>"

    myMail.From = "Example@microsoft.com"

    myMail.To = "Someone@microsoft.com"

    myMail.Subject = "Sample Message"

    myMail.BodyFormat = 0

    myMail.MailFormat = 0

    myMail.Body = HTML

    myMail.Send

    Set myMail = Nothing

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply