FWH MAIL - MAPI

Post Reply
User avatar
TimStone
Posts: 2536
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

FWH MAIL - MAPI

Post by TimStone »

I am able to use FWH MAIL / MAPI successfully with Outlook. Anytime I send an email in my application, it opens in Outlook and allows me to send it. I simply call this function within my program:

Code: Select all

FUNCTION SendMAPIMail2( MailTo, cSndFile, cText, cSubj )
    // Send MAPI mail originates email to the MAPI client
    //  Updated:    8/2/2015 2:16:52 PM
    LOCAL oMail
      DEFINE MAIL oMail ;
         SUBJECT cSubj ;
         TEXT cText ;
         FILES cSndFile, cSndFile ;
         FROM USER ;
         TO MailTo
      ACTIVATE MAIL oMail
RETURN( .t. )
 
This is great for individual emails. However, I have a need to send out emails, using MAPI, unattended. I may be sending 30 emails, and I do not want them to display in Outlook and wait for a response. They just need to go out. Of course I can do this with SMTP, etc. but Outlook would be far more productive.

Is there a setting or code that can be used to simply have Outlook pass through the emails ?

Tim
Tim Stone
http://www.MasterLinkSoftware.com
timstone@masterlinksoftware.com
Using: FWH 19.06 with Harbour 3.2.0 / Microsoft Visual Studio Community 2019
dtussman
Posts: 78
Joined: Sat Jun 06, 2015 6:57 pm

Re: FWH MAIL - MAPI

Post by dtussman »

I am able to send unattended emails through Outlook using CDO. You just have to set the port to 25.
User avatar
TimStone
Posts: 2536
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

Re: FWH MAIL - MAPI

Post by TimStone »

I use CDO direct to an SMTP server, but have not seen it use Outlook.

I have 3 options.
1) SMTP
2) CDO
3) MAPI

The first two go directly to the SMTP server. However, there are some advantages to using MAPI. The problem is that it brings up outlook each time. That is fine for individual emails, but if I'm sending a group of emails automatically, it won't work out.

Maybe you could share some code on how you use CDO with Outlook ?

Tim
Tim Stone
http://www.MasterLinkSoftware.com
timstone@masterlinksoftware.com
Using: FWH 19.06 with Harbour 3.2.0 / Microsoft Visual Studio Community 2019
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Re: FWH MAIL - MAPI

Post by gkuhnert »

Tim,

maybe this code helps you in any way sending mails via Outlook:

Code: Select all

static function SendTestMail()
local oMail := CreateOutlookMail()
    oMail:Send()
return .t.

static function CreateOutlookMail()
local oItem
local oOutlook := GetOutlookObject()
    oItem := osOutlook:Application:CreateItem(0)
    oItem:Subject := "Mail to myself"
    oItem:Body := "Body of my testmail"
    oItem:Recipients():Add("...") // your recipient here!
return oItem

static function GetOutlookObject()
local oOutlook
    TRY
        oOutlook := GetActiveObject ( "Outlook.Application" )
    CATCH
        TRY
        oOutlook := CREATEOBJECT( "Outlook.Application" )
        CATCH
                MsgStop("Cannot start outlook!")
                return nil
            END
        END
    ENDIF
return oOutlook
 
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: FWH MAIL - MAPI

Post by Marc Venken »

Tim,

If you leave out the

From User

in the program, it send by outlook, but with no action from the user. If that is what you mean.
The mails are however in the outbox, and you don't want that ?

Marc
Marc Venken
Using: FWH 20.08 with Harbour
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: FWH MAIL - MAPI

Post by Marc Venken »

Is this also possible for Thunderbird and others ?

Marc

gkuhnert wrote:Tim,

maybe this code helps you in any way sending mails via Outlook:

Code: Select all

static function SendTestMail()
local oMail := CreateOutlookMail()
    oMail:Send()
return .t.

static function CreateOutlookMail()
local oItem
local oOutlook := GetOutlookObject()
    oItem := osOutlook:Application:CreateItem(0)
    oItem:Subject := "Mail to myself"
    oItem:Body := "Body of my testmail"
    oItem:Recipients():Add("...") // your recipient here!
return oItem

static function GetOutlookObject()
local oOutlook
    TRY
        oOutlook := GetActiveObject ( "Outlook.Application" )
    CATCH
        TRY
        oOutlook := CREATEOBJECT( "Outlook.Application" )
        CATCH
                MsgStop("Cannot start outlook!")
                return nil
            END
        END
    ENDIF
return oOutlook
 
Marc Venken
Using: FWH 20.08 with Harbour
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Re: FWH MAIL - MAPI

Post by gkuhnert »

Marc,

did you already try to use the TMail Class?

Code: Select all

oMail:=TMail():New()
oMail:cSubject:="your subject"
oMail:aRecipients:={"..."} // your recipient(s)
oMail:cNoteText:= "your text"
oMail:Activate()
oMail:End()
 
I've never made a special routine for thunderbird, but some of our customers say that our general routine works fine for them. Thunderbird has to be the standard mail program though!
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: FWH MAIL - MAPI

Post by Marc Venken »

Gilbert,

Never used it. I have a app. where I use it the same way as mentioned by Tim above.

Will look into it, because it seems to have much more options.

For reading is the pop3 class ok ? I can read mails with it, but it always deletes them on the server, even If I put
oInMail:lDelMsgs := .F. //

Code: Select all

function GetMail()

   local oInMail

   oWnd:SetMsg( "Geting Internet email..." )

   oInMail = TPop3():New( "194.224.203.2",, "<Your username>", "<Your password>" )  // mail server IP

  oInMail:lDelMsgs  := .F.  // 

   oInMail:bConnecting = { || oWnd:SetMsg( "Connecting to 194.224.203.2..." ) }
   oInMail:bConnected  = { || oWnd:SetMsg( "Connected" ) }
   oInMail:bDone       = { || ReadEmails( oInMail ) }

   oInMail:GetMail()

return nil

//----------------------------------------------------------------------------//

function ReadEmails( oInMail )

   local n

   MsgInfo( "Total emails: " + Str( Len( oInMail:aMsgs ) ) )

   for n = 1 to Len( oInMail:aMsgs )
      MsgInfo( oInMail:aMsgs[ n ] )
   next

return nil
 



Marc
Marc Venken
Using: FWH 20.08 with Harbour
User avatar
gkuhnert
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands
Contact:

Re: FWH MAIL - MAPI

Post by gkuhnert »

Marc,

sorry, I never used TPOP3, maybe someone else can help?
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FWH MAIL - MAPI

Post by James Bott »

Marc,

Did you see my response to your testing on the other thread. I'm pretty sure it is your test routine that is the problem and the mails are still there.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Post Reply