Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to extract attached database mail?

Author  Topic 

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-01-27 : 14:51:22
Hello,

Anybody know how to extract attached email from sql database.

I have database mail. I sent an email with attached file.
I can see thoes records inside msdb database.
use msdb
select * from sysmail_attachments

How do i extract attachment?
I am using SQL Server 2005


exec msdb..Sp_send_dbmail
@profile_name = 'MAILPROFILE',
@recipients = 'me@test.net',
@subject = 'test message',
@body = 'TEST',
@file_attachments='D:\My_Documents\test.doc'

Now i have to restore that attachment file.



revdnrdy
Posting Yak Master

220 Posts

Posted - 2009-01-27 : 15:35:07
Well,

Don't put the cart before the horse on this one.. dont send the file as an attachment and then read it. You should save the file for reading and then mail it. This seems simpler to me.

Presumably your attachment is some the result of some kind of sql query. Before you email the results as an attachment you can save them to some disk location (something like C:/myfile.sql). After this you can send it off as an email attachment since it will now be safely stored somewhere.

Then later on you can simply re-import the myfile.sql using BCP (Bulk Copy Program) into the database to view it. There are several posts here on how to use BCP.

Another option is to save the results to an sql table and then send it off as an attachment. This way the data resides on your sql instance and you simply query it at your leisure.



r&r



Go to Top of Page

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-01-27 : 15:45:28
Thanks for reply.
I have alredy database. But i don't have source file. Now i have to restore thoes attach file from msdb..sysmail_attachments table.
Go to Top of Page

revdnrdy
Posting Yak Master

220 Posts

Posted - 2009-01-27 : 15:57:50
quote:
Originally posted by rudba

Thanks for reply.
I have alredy database. But i don't have source file. Now i have to restore thoes attach file from msdb..sysmail_attachments table.


Can you give a little more detail as to what you want to do? What do you mean by 'restoring attachments' and 'source files'.

Are you trying to restore a data table with a word document? If so why not just restore the mdf file? You are backing up your system aren't you ?

r&r
Go to Top of Page

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-01-27 : 16:15:47
well, i have sql server 2005. There are list of data on msdb..sysmail_attachments table. These mail sent using 3rd party software.
In sysmail_attachments table, there are fields filename, size, attachment. So i have to retrive attach file from attachment file.

"Restoring" means, need to copy that attached file into my computer.


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-27 : 16:39:41
As far as I know, there is no builtin tool to do this.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-01-27 : 16:51:17
So, how do we retrive thoes attach file? Any idea?
Go to Top of Page

SQLSoaker
Posting Yak Master

169 Posts

Posted - 2009-01-27 : 17:50:35
How about just emailing it to yourself!!! Seems silly but I think this is what you're looking for.
Go to Top of Page
   

- Advertisement -