Solved

Send Mail using SMTP & CDOSYS

Posted on 2004-10-20
15
279 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

757 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

22 Experts available now in Live!

Get 1:1 Help Now