从安装程序发送信息 - 自定义页面字段和日志

时间:2014-05-06 21:54:24

标签: inno-setup

我正在尝试创建一个能够发送一些日志的Inno安装程序安装程序,还有一个我自定义页面的错误报告文本:

image of custom page with various entry fields

在下面的代码中,我尝试导入我在(MSDN) SmtpMail.Send Method中找到的函数,但没有成功:

var
  ExtraPage : TInputQueryWizardPage;
  RichEditViewer: TRichEditViewer;
  labelchar,max_char:TLabel;
  Installer_bug,Content_bug: TNewRadioButton;

function SetFocus(hWnd: HWND): HWND;external 'SetFocus@user32.dll stdcall';
function GetSystemMetrics (nIndex: Integer): Integer;external 'GetSystemMetrics@User32.dll stdcall setuponly';
//function Send(message: MailMessage); external 'Send@System.Web.dll stdcall setuponly';

procedure isAt(Sender: TObject; var Key: Char);
begin
  if Key ='@' then begin
    Key := #0;
    SetFocus(ExtraPage.Edits[4].Handle);
  end;
end;

procedure NumbersOnly(Sender:TObject; var Key: Char);
var s:string;
begin
  s := ('1234567890'#8);
  if pos(key,s) =0 then 
    Key:=#0;
end;

procedure OffsetPageItem(Page: TInputQueryWizardPage; Index, Offset: Integer);
begin
//Labels
  Page.PromptLabels[Index].SetBounds(10,Offset,55,30);

//Name field
  Page.Edits[Index].SetBounds(100,Offset,200,40);

//Resolution field
  if Index=1 then
    Page.Edits[Index].SetBounds(100,Offset,40,40);
    Page.Edits[Index].MaxLength:=4

//x field
  if Index=2 then begin
    Page.Edits[Index].SetBounds(160,Offset,40,40);
    Page.PromptLabels[Index].SetBounds(145,Offset+3,10,20);
    Page.Edits[Index].MaxLength:=4
  end;

//E-Mail field
  if Index=3 then begin
    Page.Edits[Index].SetBounds(100,Offset,130,40);
    if not (Pos('@',Page.Values[Index])=0) then
      Page.Edits[Index+1].SelectAll;
  end;

//@ field
  if Index=4 then begin
    Page.Edits[Index].SetBounds(250,Offset,70,40);
    Page.PromptLabels[Index].SetBounds(235,Offset+3,10,20);
  end;

//Description field
  if Index=5 then begin
    ExtraPage.PromptLabels[index].SetBounds(10,Offset+15,80,60);
    ExtraPage.Edits[Index].Hide;
    RichEditViewer := TRichEditViewer.Create(ExtraPage);
    RichEditViewer.ScrollBars:=ssVertical;
    with RichEditViewer do begin
      Parent:=ExtraPage.Surface;
      SetBounds(100,Offset+25,300,100);
      Text:='Having a bug? Write it here... ';
      MaxLength:=400;
    end;
  end;
end;


procedure InitializeWizard;
var
  index:Integer;

begin
  ExtraPage := CreateInputQueryPage(wpWelcome, 'E-mail sender','Add The following information!','');
  ExtraPage.SubCaptionLabel.Hide;
  //index=0;
  index:=ExtraPage.Add('Name: ', False);
  ExtraPage.Values[index]:=ExpandConstant('{computername}');
  OffsetPageItem(ExtraPage,index,10);

  //index=1;
  index:=ExtraPage.Add('Resolution: ', False);
  OffsetPageItem(ExtraPage,index,40);
  ExtraPage.Values[index]:=IntToStr(GetSystemMetrics(0));
  ExtraPage.Edits[index].OnKeyPress:=@NumbersOnly;

  //index=2;
  index:=ExtraPage.Add(' x ', False);
  OffsetPageItem(ExtraPage,index,40);
  ExtraPage.Values[index]:=IntToStr(GetSystemMetrics(1));
  ExtraPage.Edits[index].OnKeyPress:=@NumbersOnly;

  //index=3;
  index:=ExtraPage.Add('E-mail: ', False);
  OffsetPageItem(ExtraPage,index,70);
  ExtraPage.Edits[index].OnKeyPress:=@isAt;

  //index=4;
  index:=ExtraPage.Add('@', False);
  OffsetPageItem(ExtraPage,index,70);
  ExtraPage.Edits[index].OnKeyPress:=@isAt;

  //index=5;
  index:=ExtraPage.Add('Short Description:'+#10+'(How to reproduce?)', False);
  OffsetPageItem(ExtraPage,index,100);

  labelchar:=TLabel.Create(WizardForm);
  with labelchar do begin
    Parent:=ExtraPage.Surface;
    SetBounds(10,200,100,30);
    Caption:='Max number of'+#10#13+'characters: ';
  end;
  max_char:=TLabel.Create(WizardForm);
  with max_char do begin
    Parent:=ExtraPage.Surface;
    Font.Style:=[fsBold];
    SetBounds(68,213,100,30);
    Caption:=IntToStr(400);
  end;

  Installer_bug:=TNewRadioButton.Create(WizardForm)
  with Installer_bug do begin
  Parent := ExtraPage.Surface;
  SetBounds(100,100,80,20);
  Caption:='Installer bug'
  end;

  Content_bug:=TNewRadioButton.Create(WizardForm)
  with Content_bug do begin
  Parent := ExtraPage.Surface;
  SetBounds(190,100,80,20);
  Caption:='Content bug'
  end;

end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
  line:String;
//  E_mail :MailMessage;
begin
  Result := True;
  if CurPageID = ExtraPage.ID then begin
    line:=ExtraPage.PromptLabels[0].Caption + ExtraPage.Values[0] + #10;
    line:=line + ExtraPage.PromptLabels[1].Caption + ExtraPage.Values[1] + ExtraPage.PromptLabels[2].Caption+ExtraPage.Values[2] + #10;
    line:=line + ExtraPage.PromptLabels[3].Caption + ExtraPage.Values[3] + ExtraPage.PromptLabels[4].Caption+ExtraPage.Values[4] + #10;
    line:=line +'Type: ';
    if Installer_bug.Checked then
      line:=line + Installer_bug.Caption + #10;
    if Content_bug.Checked then
      line:=line + Content_bug.Caption + #10;
    line:=line + ExtraPage.PromptLabels[5].Caption + #10#13;
    line:=line + RichEditViewer.Text;

    SaveStringToFile(ExpandConstant('{src}\test.txt'),line,false);

//    E_mail:=MailMessage.Create(WizardForm);
//    E_mail.From= "test@sdsd.com"
//    E_mail.To = "test@gmail.com"
//    E_mail.Subject="test";
//    SmtpMail.SmtpServer= "MyMailServer";
//    SmtpMail.Send(E_mail);

  end;
end;

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,这就是我所做的......

bmail:

bmail -s smtp.example.net -t you@example.com -f me@example.net -h ^
  -a "mail subject" -b "message text"

您也可以编写自己的邮件程序来执行。

[Run]
begin
// need to email Version
//  blat -to %eMail% -f %eMail% %subj% %server% %debug% %x%
  ExtractTemporaryFile('blat.exe');
  connExe:=ExpandConstant('{tmp}')+'\blat.exe';
  connTxt := ' -to ' + E_mail.From.text + ' -f '+ E_mail.To.Text + E_mail.Subject.Text + 'SmtpMail.SmtpServer.text' + ExpandConstant('{tmp}\log.log');
  Log('The Value is connTxt: ' + connTxt );
  if Exec(connExe, connTxt, '' , SW_HIDE, ewWaitUntilTerminated, ResultCode) then
    begin
     //MsgBox(IntToStr(ResultCode), mbError, mb_Ok);
    connTxt := ' -to ' + E_mail.From.text + ' -f '+ E_mail.To.Text + E_mail.Subject.Text + 'SmtpMail.SmtpServer.text' + ExpandConstant('{tmp}\log.log');
     ExpandConstant('{tmp}\log.log');
     Log('The Value is connTxt: ' + connTxt );
     if Exec(connExe, connTxt, '' , SW_HIDE, ewWaitUntilTerminated, ResultCode) then
      begin
        MsgBox( 'The '+ E_mail.Subject.Text + ' Email has been sent' , mbInformation, mb_Ok);
        result := True;
       end;
    end;
end;

警告名称更改以解决问题,并且未按原样进行全面测试。 @TLama是对的,但为什么不使用应用程序发送调试消息?