Mapi Outlook .. send mail silently

Mapi Outlook .. send mail silently

Postby Rick Lipkin » Sat Dec 07, 2019 7:19 pm

To All

Below is the code to create a Mapi call to Outlook to create an Outlook e-mail ... however, I would like the whole process be silent and be able to launch the SEND button automatically without being seen nor have any interaction with the user.

Image

When I run the code .. an Outlook e-mail is generated, but the user has to click on the Send button ... unfortunately I can not use CDO .. because my client has a "blurb" "This came from the internet warning" embedded in the CDO text and for security reasons, the client has SMTP closed off but to all registered devices like MFP, multi function printers that scan to e-mail.

The only other option is to use their corporate Outlook client.... as you can see .. I can create the e-mail, but it takes the client to click the send button .. Any idea on how to make the entire process silent and be able to button:Click() the Send button to launch the e-mail ...

Appreciate any advice and help

Thanks
Rick Lipkin


Code: Select all  Expand view  RUN

//----

#Include "FiveWin.ch"
#Include "Mail.ch"

//----------------------------
Func Main()

Local oDlg
Local oSay1,cSay1,oSay2,cSay2
LOCAL oBtn1,oBtn2

Local oSubject,oTo
Local cSubject,cTo
Local oMemo,cMemo
Local oFontB


cSubject := space(50)
cTo      := Space(40)
cMemo    := "Please fund my trip to the Bahamas"
cSubject := "Trip to the Bahamas"
cTo      := substr("r1.1955@live.com"+space(40),1,40)


oFontB  := TFont():New("Ms Sans Serif",,-6,.F.,.T. ,,,,.F. )

DEFINE DIALOG oDlg RESOURCE "MEMO"       ;

       cSay1 := "Subject"
       cSay2 := "To"

       REDEFINE SAY oSay1 var cSay1 ID 301 of oDlg UPDATE
                    oSay1:SetFont( oFontB )
       REDEFINE SAY oSay2 var cSay2 ID 300 of oDlg UPDATE
                    oSay2:SetFont( oFontB )

       REDEFINE GET oSubject var cSubject ID 303 of oDlg UPDATE
       REDEFINE GET oTo      var cTo      ID 302 of oDlg UPDATE


       REDEFINE GET oMEMO VAR cMEMO MEMO ID 304 of oDlg UPDATE



       REDEFINE BTNBMP oBtn1 ID 111 of oDlg   ;
         PROMPT "Create Mail" LEFT 2007;
         ACTION ( _SendMapiMail( cTo, cMemo, cSubject , oDLg ) )


       REDEFINE BTNBMP oBtn2 ID 112 OF oDlg   ;
         PROMPT "Cancel" LEFT 2007;
         ACTION ( oDlg:END() )

ACTIVATE DIALOG oDlg ;
          ON INIT( oDlg:Hide(),oBtn1:Click() );
          VALID (!GETKEYSTATE( 27 ))  // do not allow esc key here

Release Font oFontB

Return( nil )

//---------------------------------
Static Func _SendMAPIMail( MailTo, cText, cSubj,oDlg )

PRIVATE oMail

MailTo := TRIM( MailTo )



DEFINE MAIL oMail ;
       SUBJECT cSubj ;
       TEXT cText ;
       FROM USER ;
       TO MailTo

ACTIVATE MAIL oMail

oMail:ENd()

oDlg:Show()
oDlg:ENd()


RETURN( .t. )
 
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Mapi Outlook .. send mail silently

Postby Marc Vanzegbroeck » Sun Dec 08, 2019 8:32 am

Rick,

Maybe you can use blat.exe to send email for this customer.
I also have two options in my program. If the file blat.exe exist in de program-directory, it use blat.exe, otherwise the normal way.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Mapi Outlook .. send mail silently

Postby Jimmy » Mon Dec 09, 2019 9:16 pm

hi,

i'm a Fivewin Newbiew so excuse my Question :

the Snapshot show Outlook Client which you get with
Code: Select all  Expand view  RUN

   ::oItem := ::oItem:dynamicCast( ActiveXObject() )
   ::oItem:Display()

so you write your Email "in" Outlook :?:

---

i write my Email in a RTF Control and send it via MAPI to Outlook "Out" Basket
Outlook is configure to look for new Email every xxx Minute so it is send "automatic"

there was a Trick to "reduce" Time between Outlook go online to search for new Email.
i have to search it while i do not use it. i doen't matter if a Email is send 1 Hour later

---

now i have written a Email Client using harbour hbTIP LIB which support SSL.
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Mapi Outlook .. send mail silently

Postby TimStone » Tue Dec 10, 2019 11:00 pm

Rick,

I wanted to do the same thing. MAPI is an excellent solution, but when we have a series of automated emails, that is just not an option to click on every one of them.

I looked for the option a while back, but could not find one. I shall try to look again.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Mapi Outlook .. send mail silently

Postby Rick Lipkin » Wed Dec 11, 2019 2:14 pm

Tim

Thanks ... automating Outlook is my clients choice ... I welcome your efforts!

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Mapi Outlook .. send mail silently

Postby Jimmy » Thu Dec 12, 2019 2:49 am

sorry about 1st Mail ... your Form look like Outlook ;)

i'm still a FiveWin User so i do not know if my Idea work under FiveWin:

Code: Select all  Expand view  RUN
Static Func _SendMAPIMail( MailTo, cText, cSubj,oDlg )
LOCAL nRet := 0
LOCAL oMail := TMail():New(cSubject, cNoteText, cMsgType, cConversationID,;
                           dDate, cTime, lReceipt, lFromUSer, aOrigin, aRecipients,;
                           aFiles )
   oMail:Activate()
   // Result MAPISendMail()
   nRet := oMail:nRetCode
   oMail:End()
RETURN nRet
 
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Mapi Outlook .. send mail silently

Postby karinha » Fri Dec 13, 2019 3:50 pm

For new users, C:\FWH\SAMPLES\MAPLOOK.PRG - complete.

Code: Select all  Expand view  RUN

#include "FiveWin.ch"
#include "Mail.ch"

#Define CLR_MENTA       nRGB( 221, 255, 238 ) //-> Cor de Menta
#Define CLR_SOFTYELLOW nRGB( 255, 251, 225 )

MEMVAR oDlg

FUNCTION Main()

   LOCAL oSay1, cSay1, oSay2, cSay2, oSay3, cSay3, oBtn1, oBtn2,             ;
         oSubject, oTo, cSubject, cTo, oMemo, cMemo, oFontB, oFnt, oFont

   cSubject := SPACE( 50 )
   cTo      := SPACE( 40 )

   // cMemo    :=  SPACE(1000) //"Please fund my trip to the Bahamas"
   cMemo    :=  "cMemo - Corpo do email - Email body"
   cSubject := "cSubject -> Assunto do email"
   cTo      := substr( "kapiabafwh@gmail.com" + space( 40 ), 1, 40 )

   cSay1 := "Assunto(Subject):"
   cSay2 := "Para(To):"

   SetBalloon( .T. )
   SkinButtons()
   SetGetColorFocus( CLR_MENTA )

   tGet():lDisColors  := .F.
   tGet():nClrTextDis := CLR_HBLUE
   tGet():nClrPaneDis := CLR_SOFTYELLOW

   DEFINE FONT oFnt    NAME "Ms Sans Serif" SIZE 0,  14 BOLD
   DEFINE FONT oFont   NAME "Ms Sans Serif" SIZE 0, -14 BOLD

   DEFINE DIALOG oDlg RESOURCE "MEMO"

   oDlg:lHelpIcon := .F.

   REDEFINE SAY oSay1 VAR cSay1 ID 401 of oDlg UPDATE

   oSay1:SetFont( oFont )

   REDEFINE SAY oSay2 VAR cSay2 ID 402 of oDlg UPDATE

   oSay2:SetFont( oFont )

   REDEFINE SAY oSay3 VAR cSay3 ID 403 of oDlg UPDATE

   oSay3:SetFont( oFont )

   //    cSubject := "cSubject -> Assunto do email"
   REDEFINE GET oSubject VAR cSubject ID 302 OF oDlg PICTURE "@K" UPDATE     ;
      FONT oFnt COLORS CLR_BLACK, CLR_WHITE

   // cTo      := substr( "kapiabafwh@gmail.com" + space( 40 ), 1, 40 )
   REDEFINE GET oTo      VAR cTo      ID 303 OF oDlg PICTURE "@K" UPDATE     ;
      FONT oFnt COLORS CLR_BLACK, CLR_WHITE

   // cMemo    :=  "cMemo - Corpo do email - Email body"
   REDEFINE GET oMEMO VAR cMEMO MEMO ID 304 OF oDlg UPDATE FONT oFont

   REDEFINE BTNBMP oBtn1 ID 111 of oDlg 2007                                 ;
      ACTION ( _SendMapiMail( cTo, cMemo, cSubject ) )

   oBtn1:cToolTip := "Crie e envie o email"

   REDEFINE BTNBMP oBtn2 ID 112 OF oDlg 2007                                 ;
      ACTION ( oDlg:End() )

   oBtn2:cToolTip := "Saida - Exit"

   SET FONT OF oBtn1 TO oFont
   SET FONT OF oBtn2 TO oFont

   ACTIVATE DIALOG oDlg CENTERED

   RELEASE Font oFnt
   RELEASE Font oFont

RETURN NIL

STATIC FUNC _SendMAPIMail( MailTo, cText, cSubj )

   LOCAL oMail, nRet := .F.

   MailTo := TRIM( MailTo )

   DEFINE MAIL oMail ;
      SUBJECT cSubj  ;
      TEXT cText     ;
      FROM USER      ;
      TO MailTo

   ACTIVATE MAIL oMail

   nRet := oMail:nRetCode

   IF nRet = 0

     MsgInfo( "Email Send", "Email Send" )

   ENDIF

   oMail:End()

RETURN NIL
 



// MAPLOOK.RC
Code: Select all  Expand view  RUN

MEMO DIALOG 209, 93, 187, 200
STYLE DS_ABSALIGN | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Enviar email "
FONT 8, "Arial"
{
 EDITTEXT 302, 0, 20, 187, 12
 EDITTEXT 303, 0, 50, 187, 12
 EDITTEXT 304, 3, 80, 180, 96, ES_MULTILINE | ES_WANTRETURN | WS_BORDER | WS_VSCROLL | WS_TABSTOP
 PUSHBUTTON "&Criar eMail", 111, 32, 179, 70, 16, BS_LEFTTEXT | WS_TABSTOP
 PUSHBUTTON "&Saida", 112, 104, 179, 50, 16, BS_LEFTTEXT | WS_TABSTOP
 LTEXT "Assunto(Subject):", 401, 0, 6, 184, 12, NOT WS_GROUP
 LTEXT "Para(To):", 402, 0, 36, 184, 12, NOT WS_GROUP
 LTEXT "Corpo do Email - Email body", 403, 0, 66, 180, 12, NOT WS_GROUP
}
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Mapi Outlook .. send mail silently

Postby TimStone » Fri Dec 13, 2019 4:49 pm

karinha,

We have no problem with creating emails for MAPI, as your example does.

The problem is that each time you send a MAPI mail, it pops up the email in the client ( Outlook ) and does not send it until you hit the send button.

In my case, I have the system send automatic emails in the middle of the night. These include thank you notes and service reminders. Currently I have to use SMTP for this process, but we would love to have it go through the MAPI client so both the outgoing, and any incoming, emails can be tracked along side all other emails the business may send.

We need to write the email from our application directly to the Outlook outbox where the system will automatically send it when it does it's send/receive cycle. So far we have not found a workable solution for this.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Mapi Outlook .. send mail silently

Postby karinha » Fri Dec 13, 2019 5:13 pm

Master Tim, in this case, I use the easy to control RMAIL.PRG for mass emailing.

http://forums.fivetechsupport.com/viewtopic.php?f=6&t=36815&p=219619&hilit=rmail#p219619

Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Mapi Outlook .. send mail silently

Postby TimStone » Fri Dec 13, 2019 6:44 pm

In my program, the emails are not "mass", just daily followups. They are sent automatically in the middle of the night.

It works to use SMTP, but then we don't have them in Outlook. Also most of my clients have no idea how to setup SMTP, so that is an issue.

Apparently the API for Outlook does not include a direct method. Most solutions described on the net do have a method for dropping the email in the Outbox, but I have to figure out a translation for that from the old VB code, or C# code, that these folks are calling.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2950
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Mapi Outlook .. send mail silently

Postby Jimmy » Sat Dec 14, 2019 8:20 am

hi,

sorry to ask again : is your Snapshot Outlook or not :?:

my 1st Msg was about Outlook "Send Mail Form" which is called with Outlook Method Display()

---

what is in your HB_ISLOG( 7 ) when call MAIL :?:

c:\fwh\source\winapi\mapi.c
Code: Select all  Expand view  RUN
HB_FUNC( MAPISENDMAIL )
   ...
      lpfnMAPISendMail = ( LPMAPISENDMAIL ) GetProcAddress( hMapiLib, "MAPISendMail");
// this line  
      nFlags = IF( ( HB_ISLOG( 7 ) && hb_parl( 7 ) ), MAPI_DIALOG, 0 ) ;
 

i guess
Code: Select all  Expand view  RUN
  ( HB_ISLOG( 7 ) && hb_parl( 7 )

is .T. so
Code: Select all  Expand view  RUN
  nFlags = MAPI_DIALOG

if nFlags = 0 you will get no Dialog
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Mapi Outlook .. send mail silently

Postby Jack » Fri Dec 20, 2019 9:24 am

Hi ,
I think i have the solution , if you place the instruction oMailItem:Invoke("Send") , it is in silent mode .

Good luk and marry Christmas .

Philippe

#include "fivewin.ch"
function main()
local oOutLook,oMailItem
oOutLook := TOleAuto():New("Outlook.Application")
oMailItem := oOutLook:Invoke("CreateItem", 0)
oMailitem:to:="ph.jacquet@skynet.be"
oMailItem:Recipients:Add("jacquetlg@yahoo.fr")
oMailitem:CC:= "jclip@skynet.be"
oMailItem:Subject := "Sujet de mail en direct"
oMailItem:Body := "Le texte principal"
*if ! empty(cPdf)
* oMailItem:Attachments:Add(cPdf)
*endif
oMailItem:display(.F.)
oMailItem:Invoke("Send")
sysrefresh()
*
return .T.
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: Mapi Outlook .. send mail silently

Postby Rick Lipkin » Fri Dec 20, 2019 7:02 pm

Phillippe

Your code works well except .. the e-mail goes to the Outlook Outbox and it is never sent ..

Image

Definitly on the right track ... any suggestions ?

Rick Lipkin


Code: Select all  Expand view  RUN

#Include "FiveWin.ch"

//----------------------------
Func Main()

Local cSubject,cTo,cOther,cBody
Local oOutlook,oMailItem,cCC

cTo      := "dbrown@doi.sc.gov"
cOther   := "mmills@doi.sc.gov"
cCC      := "twatson@doi.sc.gov"
cSubject := "Test Silent Email"
cBody    := "This is the body of the e-mail"


oOutLook  := TOleAuto():New("Outlook.Application")
oMailItem := oOutLook:Invoke("CreateItem", 0)

oMailitem:to := cTo
oMailItem:Recipients:Add( cOther )
oMailitem:CC:= cCC
oMailItem:Subject := cSubject
oMailItem:Body := cBody

*if ! empty(cPdf)
* oMailItem:Attachments:Add(cPdf)
*endif

oMailItem:display(.F.)
oMailItem:Invoke("Send")
sysrefresh()

msginfo( "E-mail Sent" )

return .T.
 
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Mapi Outlook .. send mail silently

Postby Jimmy » Fri Dec 20, 2019 8:16 pm

Rick Lipkin wrote:Your code works well except .. the e-mail goes to the Outlook Outbox and it is never sent ..
Code: Select all  Expand view  RUN

oMailItem:display(.F.)
oMailItem:Invoke("Send")
 

even it you do not o:display(.F.) it will never "send" ... it goes to Out-Basket.
the only Way to "send" it "automatic" by Outlook.

there was a Trick to reduce Time between "automatic" but i did not found it (yet)
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Mapi Outlook .. send mail silently

Postby Rick Lipkin » Fri Dec 20, 2019 8:47 pm

To All

As it turns out the code actually works .. I learned that Outlook where I work is blocked .. I tested that with my Outlook client on my laptop .. and when I sent an e-mail with the full version of Outlook .. the message behaved the same way and got stuck in the outbox ..

This is perfect .. Thanks Philippe!!

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 68 guests