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
 General SQL Server Forums
 New to SQL Server Programming
 Send email to multiple emails with attachement

Author  Topic 

burzum
Yak Posting Veteran

55 Posts

Posted - 2012-07-19 : 16:15:36
Hi,

I will try to explain my problem as clear as possible.

I wrote a program in C# that converts file from crystal reports to .pdf. That works no problem.

My second task is to email this pdf's. Each pdf will have ONE recipient. Email addresses are stored in the database.

Is there a way I can email those pdf's from sql?

My pdf's are not stored in the database, they are in the folder on the server. But if I would have to save their path or even file itself I have no problem with that.

The reason I want to do this within the sql server, is that I ONLY want to email report if the total number is greater than 0. It's easier to do within the database itself.

I'm still trying to do this in C# as well, however it's not working out.

Any ideas or suggestions on how I can resolve this issue?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-07-19 : 16:44:50
You can use SQL Server's Database Mail feature.

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

Subscribe to my blog
Go to Top of Page

burzum
Yak Posting Veteran

55 Posts

Posted - 2012-07-19 : 16:58:58
I've look in to that, however I do not understand how would I pass the attachements and multiple recipients?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-07-19 : 23:56:01
sp_send_dbmail: http://msdn.microsoft.com/en-us/library/ms190307.aspx

You would use the @file_attachments input parameter for the attachment and then you'd compile your recipient list into @recipients and/or @copy_recipients (both semi colon separated).

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

Subscribe to my blog
Go to Top of Page

burzum
Yak Posting Veteran

55 Posts

Posted - 2012-07-20 : 11:37:32
Thank you.

Right now, I'm saving the pdf files that I want to email to multiple users are stored into the folder. Could you please give some examples on how I can save the path of the pdf file into the database so it saves it in the row for the company.

And how does it going to know to send it to specific email which is for that company. I do not want to send email one by one. I want to send them to all. (The one that has the path for it).
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-07-20 : 12:23:54
Well you're going to have to design the system to handle this. You certainly don't have to send emails one by one, but you are going to need to write code.

Putting a path to a pdf file into a table is just a normal insert or update statement.

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

Subscribe to my blog
Go to Top of Page

burzum
Yak Posting Veteran

55 Posts

Posted - 2012-07-20 : 13:18:01
Yes, that's a hole thing. Is there any example or link I can use. I just don't know what kind of approach to take.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-07-20 : 13:22:42
I don't have an example/link to share.

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

Subscribe to my blog
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-07-20 : 22:03:10
I think you are going the wrong direction. Since your C# program is generating the PDF file, naturally it will be easier to do this in your C# prog rather than via SQL (not that you can't do it there). The information you required on SQL to decide whether to send email or not can be retrieve easily via a simple SELECT statement. Though, you can't get it work in C#, why just stop there ? Find out what's the problem, post your problem on C# forum, search the net for more examples like

http://www.emailarchitect.net/easendmail/kb/csharp.aspx

And there are lots more of similar stuff out there. Just search.



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -