Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 25th, 2006, 08:31 AM
Janao Janao is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 1 Janao User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 10 sec
Reputation Power: 0
Send mail with attachment

I'm trying to send a email with attached file using the sp_send_dbmail store procedure (SQL Server 2005). The file is stored into a field of a data base table.

I succeed to send the mail with the attached file, the recipient correctly receives it (and the attached file) but
doesn't succeed in opening the file: for example if the file is a .doc the Word application doesn't read it.

In order to retrieve the content of the attached file I set the @query parameter of the sp_send_dbmail store procedure
with 'SELECT Data FROM AttachmentData WHERE AttachmentId = 78'. The type of the field 'Data' is varbinary(max).
The values of the other parameters are:

@profile_name = @MyProfileName,
@recipients = @To,
@copy_recipients = @Cc,
@subject = @Subj,
@body = @Content,
@query = @selectAtt,
@query_result_header = 0,
@attach_query_result_as_file = 1,
@query_attachment_filename = @MyFileName,
@exclude_query_output = 1,
@query_no_truncate = 1,



If the file to attach is a txt file and the @query parameter is set with 'SELECT CAST(Data AS varchar(MAX)) FROM TEST_ATTACH.dbo.AttachmentData WHERE AttachmentId = 56' the mail recipient will be able to open the file.
For the other file tipe (.gif, .doc, .pdf ecc) I try to modify the @query parameter in order to
cast to the varbinary type but it doesn't work: the recipient is not able to open the attached file.

Can help me?

Have a Nice day!
Thanks Much.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Send mail with attachment


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT