Problems with sending emails - some questions

Problems with sending emails - some questions

Postby driessen » 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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Rochinha » 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:

Code: Select all  Expand view
#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.
Rochinha
 
Posts: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo

Re: Problems with sending emails - some questions

Postby Enrico Maria Giordano » Mon Feb 19, 2007 7:48 am

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


This is a sample:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Frank Demont » Mon Feb 19, 2007 9:03 am

I use this code (based on a contribution from enrico)
Frank
Code: Select all  Expand view
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

Frank Demont
 
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Postby driessen » Mon Feb 19, 2007 9: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) ?

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

3. 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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Frank Demont » 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

2. 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
Frank Demont
 
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Postby Rochinha » Mon Feb 19, 2007 5:17 pm

Friend

In Outlook Express you need uncheck the field bellow:

Image
Rochinha
 
Posts: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo

Postby driessen » 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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Postby Manuel Valdenebro » Tue Feb 20, 2007 6: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
User avatar
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Postby Enrico Maria Giordano » Tue Feb 20, 2007 7:48 am

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Tue Feb 20, 2007 7:57 am

Manuel,

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

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

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Enrico Maria Giordano » 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:

Code: Select all  Expand view
Item.HTMLBody = "<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>"


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Manuel Valdenebro » Tue Feb 20, 2007 4: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
User avatar
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Postby James Bott » Tue Feb 20, 2007 5:19 pm

Manuel,

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

Code: Select all  Expand view
oMail:HTMLBody = "<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>"


James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Manuel Valdenebro » Wed Feb 21, 2007 10:50 am

Thank James and Enrico.
Un saludo

Manuel
User avatar
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 55 guests