Home > Back-end >  About using the shellexecute open outlook2007 send mail
About using the shellexecute open outlook2007 send mail

Time:09-15

In the mailto agreement
1: the content of the parameters of the body if contain character %, the shellexecute return value to 2, cannot open the outlook program,
2: if the body content "" in front of the characters in both Chinese and English characters #, after open the outlook will prompt command line argument is invalid in outlook, if change to Chinese" "or delete # is executed successfully,
Bosses can help solve the two problems,

CodePudding user response:

No one encountered this problem, or provide a solution is ok,

CodePudding user response:

 unit Unit1; 

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Comobj,
Dialogs, StdCtrls;

Type
TForm1=class (TForm)
For: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button2: TButton;
Memo1: TMemo;
OpenDialog1: TOpenDialog;
Button3: TButton;
Procedure Button1Click (Sender: TObject);
Procedure Button2Click (Sender: TObject);
Procedure Button3Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
The function SendMailWithAttachments (Email, Subject: string; Body: Widestring; Filename: string) : Boolean;
The end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}


Function TForm1. SendMailWithAttachments (Email, Subject: string; Body: Widestring; Filename: string) : Boolean;
//email address topic names (notes) accessories: filename
Var outlook: the variant;
Item: the variant;
The begin
Try
Outlook:=CreateOLEObject (' outlook. Application);
Try
Item:=outlook. The CreateItem (0);
Item. Subject:=Subject;//theme
Item. Body:=Body;//content
If (FileName<> ") and (FileExists (FileName))
Then the item. The Attachments. The Add (FileName, 1, 1, FileName);//accessories
Item. To:=email;
Item. Send;
The finally
Outlook. Quit;
The end;
Except,
Result:=false;
exit;
The end;
Result:=true;
The end;

procedure TForm1.Button1Click(Sender: TObject);
Var Opendialog1: TOpenDialog;
S1, S2, S3, FileName: string;
The begin
S1:=Edit1. Text;
S2:=Edit2. Text;
S3:=Memo1. Text;
FileName:=Edit3. Text;
SendMailWithAttachments (S1, S2, S3, FileName);
The end;

Procedure TForm1. Button2Click (Sender: TObject);
The begin
If OpenDialog1. Execute then
Edit3. Text:=OpenDialog1. FileName;
The end;

Procedure TForm1. Button3Click (Sender: TObject);
The begin
The close;
The end;

End.


OutLook of the parameters of the operating system you want to set up, can send, code changes, is you... .
  • Related