Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xp_sendmail to email a report

Status
Not open for further replies.

desireemm

Technical User
Dec 17, 2003
50
US
I was wondering about xp_senmail can I send a report with that procedure to different departments. I wanted some information on how to create a stored procedure and have SQL do the emailing for me. Is this possible

Code:
Private Sub Command165_Click()
On Error GoTo Err_Command165_Click
    Dim objOL As Object
    Set objOL = CreateObject("Outlook.Application")
    Set ol = New Outlook.Application


   Dim appOutlook As New Outlook.Application
    Dim omItem As MailItem
    Dim ReqId As String
    
    ReqId = Me.txt1.Value
    Set omItem = appOutlook.CreateItem(olMailItem)
    
    omItem.To = "email_address"
    omItem.DeleteAfterSubmit = True
    omItem.Subject = "Your subject"
    omItem.Body = "Your email body"
    omItem.Send

Exit_Command165_Click:
    Exit Sub

Err_Command165_Click:
    MsgBox Err.Description
    Resume Exit_Command165_Click
    
End Sub
 
Yes, that is very much possible to do with xp_sendmail. Look at BOL for the full syntax for xp_sendmail.

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
The SQL Mail session must be started prior to executing xp_sendmail. Sessions can be started either automatically or with xp_startmail.
If query is specified, xp_sendmail logs in to SQL Server as a client and executes the specified query. SQL Mail makes a separate connection to SQL Server; it does not share the same connection as the original client connection issuing xp_sendmail.


Now I was reading BOL about using xp_sendmail to send reports, looks like I need to start SQL mail session which means I need to talk to the techs on the casino side..Let me explain what I mean I work in a casino but we are not part of the casino since we REGULATE IT, we work for the Tribe the casino cant do anything without our say so. We are in the process of splitting off from them since we are still on thier wires and switches thats what our teks are in the process of doing. We will be a seperate domain off their domain (basically if I got that right child domain something like that). We use their email server soon we will be using our own. So I am wondering in order for sql to perform the xp_sendmail do I need to talk to the techs to help me to do this. SQL server is on our server only so which is why I am getting this message when I execute the
XP_startmail
Code:
Error message is : Server: Msg 18030, Level 16, State 1, Line 0
xp_startmail: Either there is no default mail client or the current mail client cannot fulfill the messaging request. Please run Microsoft Outlook and set it as the default mail client.


 
ok, first think you need to do is install Outlook 2000/xp/2003 on the SQL Server. Then take a look at this FAQ faq962-4452. It covers how to setup the SQL Server to send mail.

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top