xp_sendmail and HTML output

  • Does anyone know how to use sendmail to set contenttype = text/html.

    I can't find any documentation on how to do this.

  • Have not tried it - a quick hack would be to wrap your message in HTML tags, most email clients will switch to HTML if they see a leading < tag.

    Andy

  • quote:


    Have not tried it - a quick hack would be to wrap your message in HTML tags, most email clients will switch to HTML if they see a leading < tag.

    Andy


  • That doesn't work in Exchange client.

    I'm now experimenting with CDONTS Object

    in Sql Server. It doesn't have the same ability as xp_sendmail, but it may do.

  • Well ... I was also stuck up with the same. I could not find anything with xp_sendmail. I tried the same as you ... by using CDO and changing the mime type from text/plain to text/html ... but that too did not work. I shall redo it today itself. I shall get back to you after trying out the same.

    quote:


    Does anyone know how to use sendmail to set contenttype = text/html.

    I can't find any documentation on how to do this.


    Paras Shah

    Evision Technologies

    Mumbai, India


    Paras Shah
    Evision Technologies
    Mumbai, India

  • I switched to using JMail Object in the proc and it works fine.

    JMail is available free for private use.

  • How does it work? Is it stable enough! Can you send me a test code ... so that I can just try out on my server. I do use JMail for my ASP / VB programs. Its fast and easy to send mails.

    quote:


    I switched to using JMail Object in the proc and it works fine.

    JMail is available free for private use.


    Paras Shah

    Evision Technologies

    Mumbai, India


    Paras Shah
    Evision Technologies
    Mumbai, India

  • How does it work? Is it stable enough! Can you send me a test code ... so that I can just try out on my server. I do use JMail for my ASP / VB programs. Its fast and easy to send mails.

    quote:


    I switched to using JMail Object in the proc and it works fine.

    JMail is available free for private use.


    Paras Shah

    Evision Technologies

    Mumbai, India


    Paras Shah
    Evision Technologies
    Mumbai, India

  • How does it work? Is it stable enough! Can you send me a test code ... so that I can just try out on my server. I do use JMail for my ASP / VB programs. Its fast and easy to send mails.

    quote:


    I switched to using JMail Object in the proc and it works fine.

    JMail is available free for private use.


    Paras Shah

    Evision Technologies

    Mumbai, India


    Paras Shah
    Evision Technologies
    Mumbai, India

  • Here is a proc that does it. You have to supply some of the variables, so look closely at the properties.

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

    Drop Proc Send_JMail

    go

    Create Proc Send_JMail @EMail varchar(100),

    @Sub varchar(100),

    @Mess varchar(400),

    @TN varchar(50)

    as

    set nocount on

    declare @object int,

    @hr int,

    @rc int,

    @output varchar(255),

    @description varchar(255),

    @source varchar(255),@cmd varchar(255),@tx varchar(7900),

    @Header varchar(1000),@From varchar(80),@FromName varchar(80),

    @ServerName varchar(50)

    select @Header = mail_header_html from Mail_header

    exec @hr = sp_OACreate 'Jmail.Message', @object OUT

    if @hr != 0

    begin

    select 'Create failed with ',@hr

    return 999

    end

    exec @hr = sp_OASetProperty @object, 'From', @From

    exec @hr = sp_OASetProperty @object, 'FromName', @FromName

    exec @hr = sp_OASetProperty @object, 'ServerAddress', @Servername

    exec @hr = sp_OAMethod @object, 'AddRecipient', NULL , @EMail

    exec @hr = sp_OASetProperty @object, 'Subject', @sub

    exec @hr = sp_OASetProperty @object, 'Body', @Mess

    exec @hr = sp_OASetProperty @object, 'SILENT', 'TRUE'

    exec @hr = sp_OAMethod @object, 'AddRecipientBCC', NULL , 'Another recipients email address here***'

    exec @hr = sp_OASetProperty @object, 'HTMLBody',@Mess

    -- The next part fetches data from a table and appends it to the HTML body

    -- This is instead of using xp-Sendmail's feature of an inline query statement

    declare @rid int

    select @cmd = 'declare cur cursor for select rid,tx from ' + @TN

    + ' order by rid '

    exec(@cmd)

    open cur

    fetch next from cur into @rid,@tx

    select @cmd = 'appendHTML'

    exec @hr = sp_OAMethod @Object, @cmd,null,@Header

    while @@fetch_status = 0

    begin

    select @tx = replace(@tx,char(20),' ')

    exec @hr = sp_OAMethod @Object, @cmd,null,@tx

    fetch next from cur into @rid,@tx

    end

    close cur

    deallocate cur

    /*

    Call execute to send the email

    */

    if charindex('@',@EMail) * charindex('.',@EMail) > 0

    begin

    exec @hr = sp_OAMethod @object, 'send', NULL,@ServerName

    if @hr = 0 select 'Mail Sent to ' + @EMail

    return 0

    end

    /* ********************************************************** */

    /* Catch possible errors*/

    /* ********************************************************** */

    if @hr != 0

    begin

    exec @hr = sp_OAMethod @object, 'ErrorMessage', NULL,@description

    select 'ERROR = ' + @description

    exec @hr = sp_OAGetErrorInfo @object, @source OUT, @description OUT

    select @source,@description

    return 0

    end

    /*Kill the object */

    exec @hr = sp_OADestroy @object

  • JMail rocks!

  • Be careful using a COM object from SQL Server, espeically if this proc gets used a lot.

    Steve Jones

    steve@dkranch.net

  • Steve:

    Are you referring to the memory leak problem of using COM Objects in SQL?

    I do make use of them quite a bit but I always destroy the object at the end.

    Is there another problem with using them?

  • memory leaks are this biggie. Load is another. This is overhead that is better spent somewhere else as your server gets busy. I'd hate for my database server to be spinning lots of cycles while functioning as a mail server.

    It depends, but in general I try to keep objects on another box (that can scale) like a web server.

    Steve Jones

    steve@dkranch.net

Viewing 14 posts - 1 through 13 (of 13 total)

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