Sending file contents in the body of the email with xp_sendmail

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael McGarrigle

    Sending file contents in the body of the email with xp_sendmail

    I would like to send the contents of a file using xp_sendmail however
    I do not want the file contents to be an attachment.
    I have no problem sending the file as an attachement.
    Can anybody give me an xp_sendmail example of how to do this.
    The results of a query can easily appear in the body of the email but
    all my
    attempts to include the contents of a file in the body of the email
    have not worked.

    TIA
  • Simon Hayes

    #2
    Re: Sending file contents in the body of the email with xp_sendmail


    "Michael McGarrigle" <mjm@barwonwate r.vic.gov.au> wrote in message
    news:9d0cafdc.0 502171938.6007e f9a@posting.goo gle.com...[color=blue]
    >I would like to send the contents of a file using xp_sendmail however
    > I do not want the file contents to be an attachment.
    > I have no problem sending the file as an attachement.
    > Can anybody give me an xp_sendmail example of how to do this.
    > The results of a query can easily appear in the body of the email but
    > all my
    > attempts to include the contents of a file in the body of the email
    > have not worked.
    >
    > TIA[/color]

    Rather than use xp_sendmail, you could check out xp_smtp_sendmai l:

    Dumpster & Co. provides local dumpster rental near you. Give us a call today at 866-946-8519 for a free quote!


    It has a @messagefile parameter which looks like it may do what you want.
    Otherwise, you can use xp_cmdshell to read the file into a table, then query
    the table to get the message body:

    create table ##t (col1 varchar(1000))
    insert into ##t exec master..xp_cmds hell 'type c:\myfile.txt'
    exec master..xp_send mail
    @recipients = 'someone@somewh ere.com',
    @query = 'select col1 from ##t'
    ...

    This is quite similar to example E for xp_sendmail in Books Online.

    Simon


    Comment

    Working...