Ruby Forum Ruby > Outlook, MAPI, Sending Mail

Posted by Jade Tucker (jtucker)
on 19.08.2008 00:30
Hi All,

I am trying to write a program to test that our email servers are
working properly.

I have a ruby program to send an email from a MS Outlook inbox connected
to an exchange mail server.  The program using WIN32OLE to connect to
Outlook.  The program sends an email to another email account (out of
our network) that is setup to automatically send back the email.  My
program then waits for the email to return for a max of 5 minutes before
it will fail.

The first issue I encountered was Outlook poping up a dialog box warning
me that a program was trying to send an email on my behalf.  With
Outlook 2007 I was able to disable this security restriction.

This program needs to run on a server without anyone logged in.  For
some reason this is not working as a scheduled task set to run under the
user the email account is setup for.

I am looking for any help or advice on how to get this working.  I am
getting frustrated with developing applications that run fine normaly,
but as soon as I try to run them on a schedule or invoked remotely they
start breaking.

Does anyone know of a better way to do this or can help me with my
problem?

Thanks,
JT
Posted by Jeff Miller (ibanez270dx)
on 19.08.2008 02:25
Jade Tucker wrote:
> Hi All,
> 
Hey there,
 I had to develop an application that had to interact with Outlook quite 
a bit - however, I recommend that you use MAPI/CDO via the Exchange side 
rather than through client-side outlook, since you have less 
dependencies and a less likely chance of it breaking. Check out some VB 
examples from CDOlive.com and outlookcode.com . There is great help 
there.

Good luck,
 - Jeff Miller

> I am trying to write a program to test that our email servers are
> working properly.
> 
> I have a ruby program to send an email from a MS Outlook inbox connected
> to an exchange mail server.  The program using WIN32OLE to connect to
> Outlook.  The program sends an email to another email account (out of
> our network) that is setup to automatically send back the email.  My
> program then waits for the email to return for a max of 5 minutes before
> it will fail.
> 
> The first issue I encountered was Outlook poping up a dialog box warning
> me that a program was trying to send an email on my behalf.  With
> Outlook 2007 I was able to disable this security restriction.
> 
> This program needs to run on a server without anyone logged in.  For
> some reason this is not working as a scheduled task set to run under the
> user the email account is setup for.
> 
> I am looking for any help or advice on how to get this working.  I am
> getting frustrated with developing applications that run fine normaly,
> but as soon as I try to run them on a schedule or invoked remotely they
> start breaking.
> 
> Does anyone know of a better way to do this or can help me with my
> problem?
> 
> Thanks,
> JT
Posted by Peña, Botp (Guest)
on 19.08.2008 12:33
(Received via mailing list)
From: Jade Tucker [mailto:jtucker@xojet.com]
# I am trying to write a program to test that our email servers are
# working properly. I have a ruby program to send an email from a MS
# Outlook inbox connected to an exchange mail server.  The program using

just use ruby's net/smtp and your fine. in fact, since you're coding it, 
you can do a more granular checking of your servers by

a. checking connection thru ping
b. checking service thru port 25
c. checking email fxnality by sending an email. for a sample, see my 
last post here 
http://groups.google.com/group/ruby-talk-google/browse_thread/thread/957dc5a3b17389ac

kind regards -botp
Posted by Glen Holcomb (Guest)
on 19.08.2008 16:25
(Received via mailing list)
On Tue, Aug 19, 2008 at 4:28 AM, Peña, Botp <botp@delmonte-phil.com> 
wrote:

> c. checking email fxnality by sending an email. for a sample, see my last
> post here
> http://groups.google.com/group/ruby-talk-google/browse_thread/thread/957dc5a3b17389ac
>
> kind regards -botp
>
>
>
>
>
>
Small qualifier here.  Outlook doesn't always do SMTP, it can be turned 
off
by the more Evangelical MS Admins.

--
"Hey brother Christian with your high and mighty errand, Your actions 
speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)
Posted by Jade Tucker (jtucker)
on 19.08.2008 18:20
Glen Holcomb wrote:
> On Tue, Aug 19, 2008 at 4:28 AM, Peña, Botp <botp@delmonte-phil.com> 
> wrote:
> 
>> c. checking email fxnality by sending an email. for a sample, see my last
>> post here
>> http://groups.google.com/group/ruby-talk-google/browse_thread/thread/957dc5a3b17389ac
>>
>> kind regards -botp
>>
>>
>>
>>
>>
>>
> Small qualifier here.  Outlook doesn't always do SMTP, it can be turned 
> off
> by the more Evangelical MS Admins.
> 
> --
> "Hey brother Christian with your high and mighty errand, Your actions 
> speak
> so loud, I can't hear a word you're saying."
> 
> -Greg Graffin (Bad Religion)

Thanks for the tips.  But yeah, I can't test with SMTP and I already 
have another app to do ping tests on all of our servers.

UPDATE-- I got the app to work.  I had to end up using Outlook 2003 on 
the server.  I had to use a plugin (forgot the name but i can get it) to 
modify the security settings in '03 so that it doesn't keep asking me to 
allow the message to be sent.  Part of my problem was that the Outlook 
app wanted my password everytime it tried to send an email.  I just 
checked the box to remember the password.

Also, to anyone programming something that sends an email with outlook 
03, you have to use the SyncObjects method after using message.Send or 
else it will just put it in your outbox and not send the message. It 
doesn't seem to do this in '07.  Also, 07 provides the ole method 
SendAndRecieve.

Here is a little code to clarify:

require 'win32ole'

@outlook = WIN32OLE.new('Outlook.Application')
@mapi = @outlook.GetNameSpace('MAPI')

message = @outlook.createItem(0)
message.subject('some subject')
...
message.Save
message.Send

@mapi.SyncObjects #OR with '07  @mapi.SendAndRecieve