Solved

Send Mail using SMTP & CDOSYS

Posted on 2004-10-20
15
280 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Select JOIN table 2 23
MSSQL: Replace text (typo) 7 33
Help Extract Specific in SQL 8 25
C# guarantee sql connection close 6 30
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now