Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

Send Mail using SMTP & CDOSYS

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
Jonathan Kelly
Asked:
Jonathan Kelly
  • 8
  • 3
  • 2
  • +1
1 Solution
 
MartinCMSCommented:
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
 
Jonathan KellyAuthor Commented:
i have looked at this but using it would involve adding/overwriting some dll's with some non microsoft supported dlls - correct ?
0
 
apirniaCommented:
If you want to use SQL mail you must have MS exchange as well.
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
Jonathan KellyAuthor Commented:
I DONT want to use SQL mail.

0
 
Jonathan KellyAuthor Commented:
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
 
Jonathan KellyAuthor Commented:
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
 
apirniaCommented:
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
 
arbertCommented:
"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
 
Jonathan KellyAuthor Commented:
>" 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
 
Jonathan KellyAuthor Commented:
can anyone tell me how this script works ?

http://support.microsoft.com/kb/312839/EN-US/
0
 
arbertCommented:
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
 
Jonathan KellyAuthor Commented:

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
 
arbertCommented:
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
 
Jonathan KellyAuthor Commented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now