473,803 Members | 3,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending formated Email with database mail sql 2005

1 New Member
Hi,
My objective is to send out invoice statements with database mail by means of a stored procedure.
There are two tables, Table1 is customer information, Table2 is invoice information.
Table 1 has Account Number, Customer Email, etc..
Table2 has Account Number, Invoice Number, etc..
This is one of my failed attempts trying to use Cursors.
Any suggestion on how I can accomplish this.
Thank you.

declare @msg varchar(2000),
@subject varchar(30),
@statedate varchar(50),
@accountno varchar(50),
@amountdue nchar(10),
@companyname varchar(50),
@stateaddress varchar(50),
@statecity varchar(50),
@st varchar(50),
@statezip nchar(10),
@comment varchar(50),
@statecurrent varchar(50),
@day3160 int,
@day6190 int,
@over90 int,
@fc money,
@email varchar(50),
@AccountNo1 varchar(50),
@InvoiceDate varchar(50),
@InvoiceNo varchar(50),
@Rt varchar(50),
@CustomerNo varchar(50),
@Charges varchar(50),
@Credits varchar(50),
@Balance varchar(50)


declare email_cur CURSOR
for

select StateDate, AccountNo, AmountDue,
companyName, StateAddress, StateCity,
St, StateZip, Comment,
StateCurrent, day3160, day6190,
over90, FinanceCharge, Email
from Table1
open email_cur
fetch next from email_cur into
@statedate,
@accountno,
@amountdue,
@companyname,
@stateaddress,
@statecity,
@st,
@statezip,
@comment,
@statecurrent,
@day3160,
@day6190,
@over90,
@fc,
@email

while (@@Fetch_status =0)
begin
declare email_cur1 CURSOR
for
select AccountNo, InvoiceDate,
InvoiceNo, Rt, CustomerNo,
Charges, Credits, Balance
from Table2
where accountno = @accountno
open email_cur1
fetch next from email_cur1 into
@AccountNo1,
@InvoiceDate,
@InvoiceNo,
@Rt,
@CustomerNo,
@Charges,
@Credits,
@Balance
while (@@Fetch_status =0)
begin
fetch next from email_cur1 into
@AccountNo1,
@InvoiceDate,
@InvoiceNo,
@Rt,
@CustomerNo,
@Charges,
@Credits,
@Balance
end
deallocate email_cur1

set @msg= ' html stuff e.g.
<tr>
<td width="17%">' + @InvoiceDate + '</td>
<td width="16%">' + @InvoiceNo + '</td>
<td width="7%">' + @Rt + '</td>
<td width="11%">' + @CustomerNo + '</td>
<td width="15%">' + @Charges + '</td>
<td width="17%">' + @Credits + '</td>
</tr>'

exec msdb.dbo.sp_sen d_dbmail
@profile_name = 'emailer',
@recipients=@em ail, @body=@msg,
@subject='Invoi ce Statement',
@body_format = 'HTML'

fetch next from email_cur into
@statedate,
@accountno,
@amountdue,
@companyname,
@stateaddress,
@statecity,
@st,
@statezip,
@comment,
@statecurrent,
@day3160,
@day6190,
@over90,
@fc,
@email

end
deallocate email_cur
Jun 29 '07 #1
0 1571

Sign in to post your reply or Sign up for a free account.

Similar topics

0
522
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils import mimetypes import os,string
5
2639
by: BaWork | last post by:
I have a web form where a client can select which site members to send an email to. This form is populated from the contents of the member table, so the form can have 0-x names listed on it depending on member expiration dates. When the form is submitted, the code loops through the form contents and sends an email to those members that meet the selected criteria. All this worked perfectly when I was sending text emails, but since I
5
12062
by: Brian Hanson | last post by:
Hi, I have an asp.net (vb) app where I am creating a Crystal Report, exporting it to a .pdf file and then e-mailing that report, as an attachment, to several users using System.Web.Mail.MailMessage(). One of the properties is MailMessage.To which is my recipient list. All is working well. However, when I substitute individual email addresses in the MailMessage.To string with the name of a distribution group, it fails
6
2425
by: Eduardo Rosa | last post by:
Somebody knows how I queue email using .Net? thanks a lot
3
7733
by: Sydney | last post by:
Hi, I am trying to construct a WSE 2.0 security SOAP request in VBScript on an HTML page to send off to a webservice. I think I've almost got it but I'm having an issue generating the nonce value for the UserName token. Is it possilbe at all to do this from VBScript (or jscript?)? I know I will be limited with what I can do with the SOAP message. Eg/ can't sign/encrypt it etc. Thanks,
2
10145
by: HK | last post by:
In VB.NET, I'm getting the exception "failure sending mail". I'm running VS 2005 on XP Home. This is a new install on a new PC. I've never had email problems with VS 2003, and there I could modify the SMTP settings in IIS. But with this install, there is no IIS (at least I can't find an IIS with MMC browsing the snap-ins). I suspect that is part of the problem but I don't know the solution and I have to be able to test sending email...
5
2450
by: Jai | last post by:
Hi, I am in a problem of sending mass emails(newsletter) to my website members. Actually my problem is this: I want to send newsletter to my website members. But I had given a facility for each member to choose different category of products or all products newsletter.
0
2315
by: krouxsa | last post by:
Hi There people... Please help me with this query. I want to send 1 email to multiple email addresses stored in a database. Will it be possible? I'm using SQL Server 2005 and already set up the Database mail. I also tested the mail and it works fine. My problem is sending mail to multiple emails recipients stored in a Database
9
3476
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
0
9565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.