OLE & Outlook (How to translate this Delphi code)

OLE & Outlook (How to translate this Delphi code)

Postby Maurilio Viana » Wed Jun 28, 2006 6:58 pm

Does anybody can help me to translate this Delphi code that send mail using Outlook to FW/xHarbour?

Code: Select all  Expand view
procedure TForm1.Button1Click(Sender: TObject);
var
   Outlook  : OleVariant;
   vMailItem: variant;
begin
try
   Outlook := GetActiveOleObject('Outlook.Application');
except
   Outlook := CreateOleObject('Outlook.Application');
end;
vMailItem := Outlook.CreateItem(olMailItem);
vMailItem.Recipients.Add('fulando@mundo.com.br'); // 1st recipient 
vMailItem.Recipients.Add('ciclano@mundo.com.br');  // 2dn recipient
vMailItem.Subject := 'teste de email';            // subject
vMailItem.Body := 'Este é um teste';              // mail body
vMailItem.Attachments.Add('C:\temp\arq.txt');      // Attached file
vMailItem.Send;
VarClear(Outlook);
end;
User avatar
Maurilio Viana
 
Posts: 252
Joined: Tue Oct 25, 2005 2:48 pm
Location: Garça/Garza/Heron City - Brazil

Postby James Bott » Wed Jun 28, 2006 9:05 pm

MAPI Mail Syntax:

DEFINE MAIL [ <oMail> ];
[ SUBJECT <cSubject> ];
[ TEXT <cText> ];
[ TYPE <cType> ];
[ DATE <dDate> ];
[ TIME <cTime> ];
[ CONVERSATION <cConversation> ]:
[ RECEIPT ];
[ FROM USER ];
[ FILES <cFilename1> ,<cDescript1>, <cFilenameN>, <cDescriptN> ] ];
[ ORIGIN <cOrigin> [ <cOriginAddress> ] ];
[ TO <cTarget1>, [ <cTargetAddress1> ] [ <cTargetN> [ <cTargetAddressN> ] ] ];


If the attachment file is html (has a .htm or .html extension) and you do not specify any TEXT (a message) then the file will appear in the message area.

ERRORS
If you specify a TO and the parameter is blank and you are using the FROM USER clause, the message compose box will not appear. Likewise if the filename is invalid or not found. It is best to use an error trap:

DEFINE MAIL...
ACTIVATE MAIL...

IF oMail:nRetCode!=0
MsgAlert("The message could not be sent due to an error."+CRLF+;
"MAPI error code: "+ltrim(str(oMail:nRetCode)),"Alert")
ENDIF
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Gale FORd » Wed Jun 28, 2006 10:21 pm

Hi James,

The only problem with using mapi is that the later versions of outlook popup a security warning message if you want to send without user intervention.

This Microsoft "Feature" is really irritating if you want an automatic sending feature.

I use Ole or pop3 for automatic sending.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Maurilio Viana » Thu Jun 29, 2006 11:19 am

James Bott wrote:MAPI Mail Syntax:

DEFINE MAIL [ <oMail> ];
(...)


Thanks a lot, James

Regards
Maurilio
User avatar
Maurilio Viana
 
Posts: 252
Joined: Tue Oct 25, 2005 2:48 pm
Location: Garça/Garza/Heron City - Brazil

Postby Maurilio Viana » Thu Jun 29, 2006 11:20 am

Gale FORd wrote:I use Ole or pop3 for automatic sending.


Gale, can you post a short OLE sample?

Thanks!
Maurilio
User avatar
Maurilio Viana
 
Posts: 252
Joined: Tue Oct 25, 2005 2:48 pm
Location: Garça/Garza/Heron City - Brazil

Postby Randal » Thu Jun 29, 2006 2:01 pm

Gale,

You know you can turn that off in Outlook so you don't get the message.

Regards,
Randal Ferguson
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Postby Gale FORd » Thu Jun 29, 2006 2:08 pm

Randal,

I have looked into the problem but could not find a simple solution. Microsoft has something called extended mapi that does not have that security warning but I have not dug into it yet.

Do you have a solution for Outlook 2003?
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby Gale FORd » Thu Jun 29, 2006 3:37 pm

Maurilo,

I am sending sample.
I have not used Outlook with ole for some time so when I tested this sample I found that Outlook security warning prompt came up so this may or not work for you. I have a utility installed to overide the security warning when necessary but to install this utility on all my users machines is not practical.

FUNCTION SendMail()
LOCAL oOutLook,;
oMailItem,;
oRecip,;
oAttach

/* creating the OLE object */
TRY
oOutLook := CreateObject( "Outlook.Application" )
CATCH
Alert( "ERROR! Outlook not avialable." ) /// [" + Ole2TxtError()+ "]" )
RETURN
END


oMailItem := oOutLook:CreateItem( 0 )

//Recipients
oRecip := oMailItem:Recipients()
oRecip:Add( "gale.ford@wwrowland.com" )

// Subject and body
oMailItem:Subject := "Ole Email Message"
oMailItem:Body := "This is the message body"

// Attachments
oAttach := oMailItem:Attachments()
//oAttach:Add( "g:\dispatch\who.bat" )
oAttach:Add( "c:\config.sys" )

oMailItem:Send()

/* Destroy all the created OLE objects */
oRecip := nil
oAttach := nil
oMailItem := nil
oOutLook := nil

RETURN NIL
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby James Bott » Thu Jun 29, 2006 4:44 pm

Gale,

As Randal says, I think you can turn off the warning. I don't have a copy of Outlook here, but in Outlook Express you go to Tools-Options, select the Security tab, and there is a checkbox labled "Warn me if other applications try to send mail as me." Just uncheck it.

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

Postby Gale FORd » Thu Jun 29, 2006 4:55 pm

James,

Outlook has a Security tab but there is no setting related to that warning.

I have looked into this and it is not that simple.
I recommend tsmtp() to send email quietly. Tmail() works great if you use "from user" option but for mass mailing or unattended operation I cannot recommend it.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Postby James Bott » Thu Jun 29, 2006 5:15 pm

Gale,

>but for mass mailing or unattended operation I cannot recommend it.

I agree with you on that. I would use MAPI only for occasional emails when the user may want or need to enter the address and/or when they want to retain a copy of the message in their MAPI client app.

For mass emailing SMTP is the only feasible solution.

Microsoft may have eliminated the ability to turn off the warning in later versions of Outlook since it really is a security risk to have it turned off.

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

Postby tnhoe » Thu Jun 29, 2006 6:03 pm

Outlook Redemption works around limitations imposed by the Outlook Security Patch :-

http://www.dimastr.com/redemption/
Regards

Hoe, email: easywin3@yahoo.com
User avatar
tnhoe
 
Posts: 83
Joined: Tue Nov 08, 2005 11:09 am
Location: Malaysia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 103 guests