Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Send Mail using SMTP & CDOSYS

Posted on 2004-10-20
15
Medium Priority
?
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

721 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