FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Problems with sending emails - some questions
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Problems with sending emails - some questions
Posted: Sun Feb 18, 2007 11:03 PM
Hello,

I have 3 problems concerning sending emails.



1. To send emails in my application, I use this code :

----------------------------------------------

MapiLogOn()

DEFINE MAIL oOutMail ;
SUBJECT ALLTRIM(EmOnde) ;
FILES TabAtt,"" ;
TEXT FmText FROM USER

oOutMail:aRecipients := {{ALLTRIM(LOWER(cEmail[i])),""}}
ACTIVATE MAIL oOutMail

RC := oOutMail:nRetCode

MapiLogOff()

----------------------------------------------

My email is transferred to Outlook which shows my email once again. After I have clicked "Send", my application gets a GPF while executing "MapiLogOff()". And, of course, my application is quited.

This code worked very good in FW16. Why doesn't it in FW32 ?

Does anyone know why this is happening ?


2. I have another method to send my emails : smpt.

Herefor, I use this code :

----------------------------------------------

oDummy := TSmtp():New(GetHostByName(PAR->POUTLIP))
oOutMail := TSmtp():New(GetHostByName(PAR->POUTLIP))

oOutMail:bConnecting = {|| cStat1:= "Connecting",Em2Dlg:Update() }
oOutMail:bConnected = {|| cStat2:= "Connected",Em2Dlg:Update() }
oOutMail:bDone = {|| EmSend := .T.}

oOutMail:SendMail(ALLTRIM(US->UOUTLADR),;
{ALLTRIM(LOWER(cEmail))},FmText,;
ALLTRIM(EmOnde),TabAttach)

----------------------------------------------

TabAttach is the array which contains the attachments.

There are no problems with sending my emails. But the recipient can't read the attachments. They are transferred to files like ATT00011.TXT or ATT00017.TXT while the original attachments were DOC-files or PDF-files.

What has to be done so that attachments arrive at the recipients as they were send ?


3. How can I send emails from my application to Outlook, using OLE ?


Thank you very much for any help.

Michel

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 310
Joined: Sun Jan 08, 2006 10:09 PM
Problems with sending emails - some questions
Posted: Mon Feb 19, 2007 12:32 AM
Friend,

Download and install a free component AspEmail in your system.

After register the .OCX in your machine test the code bellow:

#include "fivewin.ch"

FUNCTION Main()
   LOCAL hOLEObject
   Mail := TOleAuto():New("Persits.MailSender.4")
   Mail:Host := "smtp.yourISP.com"
   Mail:Port := 25 

   Mail:AddAddress( "emailTO@ISP.com" )
   Mail:AddAttachment( "file.txt" )

   Mail:From     := "yourEmail@yourISP.com"
   Mail:FromName := "Your Name Here"

   Mail:UserName := "YourUserNameForAutenticate"
   Mail:PassWord := "YourPasswordForAutenticate"

   Mail:Subject  := "Put a subject text"
   Mail:Body     := "Put a blablabla!"
   //Mail:IsHtml   := .t. // need help to this?
   Mail:Send()
   Mail:End()
   return .t.


I use this component in my softwares and work fine.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Problems with sending emails - some questions
Posted: Mon Feb 19, 2007 07:48 AM
driessen wrote:3. How can I send emails from my application to Outlook, using OLE ?


This is a sample:

#define olMailItem 0


FUNCTION MAIN()

    LOCAL oOutlook, oMail

    oOutlook = CREATEOBJECT( "Outlook.Application" )

    oMail = oOutlook:CreateItem( olMailItem )

    oMail:Recipients:Add( "e.m.giordano@emagsoftware.it" )

    oMail:Subject = "Test"

    oMail:Attachments:Add( "c:\xharbour\image.jpg" )

    oMail:HTMLBody = MEMOREAD( "c:\xharbour\test.htm" )

    oMail:Send()

    oOutlook:Quit()

    RETURN NIL


EMG
Posts: 142
Joined: Sun Oct 09, 2005 10:59 AM
Problems with sending emails - some questions
Posted: Mon Feb 19, 2007 09:03 AM
I use this code (based on a contribution from enrico)
Frank
PROC SendOLMail( aTo, c_Msg, c_Subject, a_Files , c_HTML )
**************************************************************************************************	

LOCAL oOutlook, oMail , el

TRY
  oOutlook := GetActiveObject( "Outlook.Application" )
CATCH
  TRY
     oOutlook := CreateObject( "Outlook.Application" )
   CATCH
      ?  "ERROR! Outlook not avialable. [" + Ole2TxtError()+ "]"
      RETURN
   END
END
    
oMail := oOutlook:CreateItem( olMailItem )

FOR EACH el IN aTo
  oMail:Recipients:Add( el )
NEXT
    
IF ! IsNil(c_Subject)
  oMail:Subject := c_Subject //"Test message"
END
		
IF ! IsNil(c_Msg)
  oMail:Body := c_Msg
END
IF ! IsNil(c_Html)
  oMail:HTMLBody := c_Html
END

IF ! IsNil(a_Files) .AND. IsArray(a_Files)
  FOR EACH el IN a_Files
    oMail:Attachments:Add( el )
  NEXT
END
    
oMail:Display = .T.

oMail := nil

RETURN
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Problems with sending emails - some questions
Posted: Mon Feb 19, 2007 09:51 AM

Thanks a lot, guys.

You were a great help.

Your examples just work fine except for three things.

  1. Outlook always asks for permition to send an email through Outlook.

How can I prevent asking this question (sometimes more than once) ?

  1. What if an email isn't send after all ? (I mean : isn't excepted by Outlook for one reason or another).

  2. If you use "DEFINE MAIL ..." you can add the specification "FROM USER" after which the email is shown in Outlook before being send (the questions in my first point aren't asked too). Is something like that possible in your examples ?

Thanks.

Michel

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 142
Joined: Sun Oct 09, 2005 10:59 AM
Problems with sending emails - some questions
Posted: Mon Feb 19, 2007 11:16 AM
  1. Outlook always asks for permition to send an email through Outlook.

How can I prevent asking this question (sometimes more than once) ?

Maybe you find an answer in :

c:\program Files\Microsoft Office\OFFICE11\1043\VBAOL11.chm

  1. What if an email isn't send after all ? (I mean : isn't excepted by Outlook for one reason or another).

The major benefit from outlook is that 'sent items' are updated or not
Using tsmtp can also be give an answer in a log-file

Frank

Posts: 310
Joined: Sun Jan 08, 2006 10:09 PM
Problems with sending emails - some questions
Posted: Mon Feb 19, 2007 05:17 PM
Friend

In Outlook Express you need uncheck the field bellow:

Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Problems with sending emails - some questions
Posted: Mon Feb 19, 2007 11:30 PM

Rochinha,

You're right if I should use Outlook Express.

But I use Microsoft Outlook 2003 which is a part of Microsoft Office 2003.

Thanks anyway.

Michel

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 711
Joined: Thu Oct 06, 2005 09:57 PM
Problems with sending emails - some questions
Posted: Tue Feb 20, 2007 06:06 AM

Enrico,

To check, I change an old code with MAIL/FHW to your code with OLE. I have following error:

Error description Outlook.Application:
Createitem/16389 E_FAIL:_HTMLBODY.

The file "html" exist and the path is complete and correct.

oMail:HTMLBody = MEMOREAD( "c:\leb\fsoli.htm" )

Any Help ?

Regards

Un saludo



Manuel
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Problems with sending emails - some questions
Posted: Tue Feb 20, 2007 07:48 AM

Please reduce the problem to a single self-contained PRG and show it here.

EMG

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Problems with sending emails - some questions
Posted: Tue Feb 20, 2007 07:57 AM

Manuel,

I don't know if this will work but have you tried:

oMail:HTMLBody = "c:\leb\fsoli.htm"

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Problems with sending emails - some questions
Posted: Tue Feb 20, 2007 10:58 AM
James Bott wrote:Manuel,

I don't know if this will work but have you tried:

oMail:HTMLBody = "c:\leb\fsoli.htm"

James


No. From Outlook docs:

Item.HTMLBody = "<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>"


EMG
Posts: 711
Joined: Thu Oct 06, 2005 09:57 PM
Problems with sending emails - some questions
Posted: Tue Feb 20, 2007 04:56 PM
EnricoMaria wrote:Please reduce the problem to a single self-contained PRG and show it here.

EMG


FUNCTION OLEMAIL( aDir, cMsg, cAsunto, cHTML, aFiles )

LOCAL oOutlook, oMail , el

TRY
oOutlook := GetActiveObject( "Outlook.Application" )
CATCH
TRY
oOutlook := CreateObject( "Outlook.Application" )
CATCH
? "Outlook no disponible. [" + Ole2TxtError()+ "]"
RETURN nil
END
END

oMail := oOutlook:CreateItem( 0 )

FOR EACH el IN aDir
oMail:Recipients:Add( el )
NEXT

IF !EMPTY(cAsunto)
oMail:Subject := cAsunto
END

IF !EMPTY(cMsg)
oMail:Body := cMsg
END

oMail:HTMLBody = MEMOREAD("c:\leb\fsoli.htm")

oMail:Display = .T.

oMail := nil

RETURN nil
Un saludo



Manuel
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Problems with sending emails - some questions
Posted: Tue Feb 20, 2007 05:19 PM
Manuel,

Perhaps try substituting Enrico's example from the docs. This would eliminate any problem with the HTML file you are using.

oMail:HTMLBody = "<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>"


James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 711
Joined: Thu Oct 06, 2005 09:57 PM
Problems with sending emails - some questions
Posted: Wed Feb 21, 2007 10:50 AM

Thank James and Enrico.

Un saludo



Manuel