Solved

Send Mail using SMTP & CDOSYS

Posted on 2004-10-20
15
283 Views
Last Modified: 2011-10-03
Hi Experts,

Im trying to get a SQL Sever to send some email. Im confused !

I have found code at the following at
http://support.microsoft.com/kb/312839/EN-US/

but I have no idea of what its doing or how it works.

I suppose the two most important lines to start with are :

-- This is to configure a remote SMTP server.
   EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'

-- This is to configure the Server Name or IP address.
   EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', 'MailServerName'


What are these two URL's about ?
("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'
("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value'

Are they feeding in a variable to the proc or what ?


I want use a remote SMTP server on the same domain - MyDomain\SMTPServer

So how should my proc read ?

Can someone take through this proc and explain line by line whats going on.

I'm an Access/SQL developer but have never used COM.


Any help or advice of any sort would be great - thanks
















0
Comment
Question by:Jonathan Kelly
  • 8
  • 3
  • 2
  • +1
15 Comments
 
LVL 8

Expert Comment

by:MartinCMS
ID: 12359762
Have you consider using XPSMTP.dll - SQL Server SMTP Mail XP.

It much more reliable then using xp_sendmail.  Here is the following link for info on XPSMTP

http://sqldev.net/xp/xpsmtp.htm
0
 
LVL 7

Author Comment

by:Jonathan Kelly
ID: 12359805
i have looked at this but using it would involve adding/overwriting some dll's with some non microsoft supported dlls - correct ?
0
 
LVL 9

Expert Comment

by:apirnia
ID: 12360048
If you want to use SQL mail you must have MS exchange as well.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 7

Author Comment

by:Jonathan Kelly
ID: 12360118
I DONT want to use SQL mail.

0
 
LVL 7

Author Comment

by:Jonathan Kelly
ID: 12360158
apirinia: are you saing that the code at http://support.microsoft.com/kb/312839/EN-US/
uses SQL Mail ?

I thought it used SMTP not MAPI which is what Im aming for.

Also I have seen some code for NT4 servers that uses CDONTS rather that CDOSYS which seems to be alot less complicated. Will this run on Win2k servers aswell?


Can anyone explain
EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'

is doing ?
0
 
LVL 7

Author Comment

by:Jonathan Kelly
ID: 12360211
As far as I can see the CDOSYS version does not require a local SMTP server and can use an SMTP server on another box.


What do I need to do to configure that SMTP server to send my mail?
Can that SMTP server be any machine connected to the domain with SMTP running. Does it need configuration to get it working or should it run in its default state.

What about firewalls and Proxy servers?


0
 
LVL 9

Expert Comment

by:apirnia
ID: 12360922
Very interesting.... I never sent mail from my SQL because I thought I need exchange.
But according to Microsoft and the web link you provided you can.
I always sent it from my ASP pages using CDOSYS.

take a look at these links:

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21059175.html?query=&clearTAFilter=true

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_11805298.html?query=&clearTAFilter=true

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_10182193.html?query=&clearTAFilter=true
0
 
LVL 34

Expert Comment

by:arbert
ID: 12366378
"Very interesting.... I never sent mail from my SQL because I thought I need exchange."

Always been that way.....SQLMail only requires a mapi profile--doesn't have to connect to an Exchange server, and of course, CDOSYS and SMTP don't require it either....

Datrias, XPSMTP doesn't overwrite any existing dlls....More information here: http://www.sqldev.net/xp/xpsmtp.htm 

Brett
0
 
LVL 7

Author Comment

by:Jonathan Kelly
ID: 12367838
>" XPSMTP doesn't overwrite any existing dlls"

Still - I know the System Admin guy would drop kick me out the door for even suggesting such an approach.

I dont want to modify the SQL Server at all if I can avoid it.


The SMTP method above seems like an ideal approach except that I dont understand the code at all!

Im looking for someone to explain it to me




0
 
LVL 7

Author Comment

by:Jonathan Kelly
ID: 12419379
can anyone tell me how this script works ?

http://support.microsoft.com/kb/312839/EN-US/
0
 
LVL 34

Expert Comment

by:arbert
ID: 12421689
What specifically do you want to know?  The SP_OA group of procedures allow you to use an external object, just like you would in VB...Create the object, set the parms, call the methods, destroy the object....
0
 
LVL 7

Author Comment

by:Jonathan Kelly
ID: 12422805

these two lines are confusing me

-- This is to configure a remote SMTP server.
   EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'

-- This is to configure the Server Name or IP address.
   EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', 'MailServerName'


what are the urls about ?
Is a value being retieved from these URLS? Do I need to specify different URLs for my application?
0
 
LVL 34

Accepted Solution

by:
arbert earned 500 total points
ID: 12430020
No, they don't actually send anything--just part of the standard and the object model.

Of course, you do want to change your mailservername (I know you know that).

This might be a little more descriptive:
http://aspalliance.com/550
0
 
LVL 7

Author Comment

by:Jonathan Kelly
ID: 12674553
Although I still dont understand the lines of the script as stated above, arbert has helped me along. So thanks arbert.

The SQL team have decided to install outlook on the sql server so wont need the SMTP approach this time around but it would very useful to use the SMTP method for future projects.

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server / Update DB? 22 37
sql server query 12 26
RESTORE MASTER DATABASE -- NOW 2 20
Isolation level setting TSQL View 10 28
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question