Problems with sending emails - some questions
Problems with sending emails - some questions
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)),""}}
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
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)),""}}
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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Friend,
Download and install a free component AspEmail in your system.
After register the .OCX in your machine test the code bellow:
I use this component in my softwares and work fine.
Download and install a free component AspEmail in your system.
After register the .OCX in your machine test the code bellow:
Code: Select all
#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.
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Problems with sending emails - some questions
This is a sample:driessen wrote:3. How can I send emails from my application to Outlook, using OLE ?
Code: Select all
#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
-
- Posts: 142
- Joined: Sun Oct 09, 2005 10:59 am
I use this code (based on a contribution from enrico)
Frank
Frank
Code: Select all
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
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
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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
-
- Posts: 142
- Joined: Sun Oct 09, 2005 10:59 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
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
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
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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
- Manuel Valdenebro
- Posts: 706
- Joined: Thu Oct 06, 2005 9:57 pm
- Location: Málaga-España
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
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
Manuel
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
No. From Outlook docs:James Bott wrote:Manuel,
I don't know if this will work but have you tried:
oMail:HTMLBody = "c:\leb\fsoli.htm"
James
Code: Select all
Item.HTMLBody = "<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>"
- Manuel Valdenebro
- Posts: 706
- Joined: Thu Oct 06, 2005 9:57 pm
- Location: Málaga-España
FUNCTION OLEMAIL( aDir, cMsg, cAsunto, cHTML, aFiles )EnricoMaria wrote:Please reduce the problem to a single self-contained PRG and show it here.
EMG
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
Manuel
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Manuel,
Perhaps try substituting Enrico's example from the docs. This would eliminate any problem with the HTML file you are using.
James
Perhaps try substituting Enrico's example from the docs. This would eliminate any problem with the HTML file you are using.
Code: Select all
oMail:HTMLBody = "<HTML><H2>My HTML page.</H2><BODY>My body.</BODY></HTML>"
- Manuel Valdenebro
- Posts: 706
- Joined: Thu Oct 06, 2005 9:57 pm
- Location: Málaga-España