下面是两种方法调用OUTLOOK发送邮件,不过不管是哪一种,都出现以下两个问题。
第一个问题:都会弹出一个警告窗口,说什么允许、拒绝、信任之类的,如何去掉这个窗口?(15分)
第二个问题:邮件进入了寄件夹,但是一直不发出去,就算是手工开启再点发送,也是发不出去,如何解决?(15分)
procedure TForm1.Button1Click(Sender: TObject);
Var
  Outlook,Mail,Recipient:Variant;
begin
  Outlook:=CreateOleObject('Outlook.Application');
  Mail:=Outlook.CreateItem(olMailItem);
  Recipient:=Mail.Recipients.Add('[email protected]');
  Recipient.Type:=olTo;
  Mail.Subject:='主題';
  Mail.Body:='正文';
  Mail.Send;
  Outlook:=Unassigned;
end;
procedure TForm1.Button_SendClick(Sender: TObject);
var MI: _MailItem;
begin
  OutlookApplication1.AutoQuit:=False;
  OutlookApplication1.Connect;
  MI:=OutlookApplication1.CreateItem(olMailItem) as MailItem;
  //郵件發給誰
  MI.Recipients.Add('[email protected]'); 
  MI.Subject:='這是郵件的主題或者題目';
  MI.Body:=RzMemo_ifo.Text;
  //MI.Attachments.Add(Path, EmptyParam, EmptyParam,MI.Display(null); //Path是圖片的路徑
  MI.Send;    
end;

解决方案 »

  1.   

    何必要通过outlook呢,直接调用发送不就行了,我这里有个邮件处理类,给你看看,希望对你有帮助:
    Unit EMail_Code;Interface
    Uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    Const
      cBase64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/Z';
    Function QuotedPrintableEncode(mSource: String): String;
    Function QuotedPrintableDecode(mCode: String): String;
    Function EMailBase64Encode(mSource: String; mAddLine: Boolean = True): String;
    Function EMailBase64Decode(mCode: String): String;
    //Function GetTitle(Const Value: String): String;ImplementationFunction QuotedPrintableEncode(mSource: String): String;
    Var
      I, J: Integer;
    Begin
      Result := '';
      J := 0;
      For I := 1 To Length(mSource) Do Begin
          If mSource[I] In [#32..#127, #13, #10] - ['='] Then Begin
              Result := Result + mSource[I];
              Inc(J);
            End Else Begin
              Result := Result + '=' + IntToHex(Ord(mSource[I]), 2);
              Inc(J, 3);
            End;
          If mSource[I] In [#13, #10] Then J := 0;
          If J >= 70 Then Begin
              Result := Result + #13#10;
              J := 0;
            End;
        End;
    End; { QuotedPrintableEncode }Function QuotedPrintableDecode(mCode: String): String;
    Var
      I, J, L: Integer;
    Begin
      Result := '';
      J := 0;
      mCode := AdjustLineBreaks(mCode);
      L := Length(mCode);
      I := 1;
      While I <= L Do Begin
          If mCode[I] = '=' Then Begin
              Result := Result + Chr(StrToIntDef('$' + Copy(mCode, I + 1, 2), 0));
              Inc(J, 3);
              Inc(I, 3);
            End Else If mCode[I] In [#13, #10] Then Begin
              If J < 70 Then Result := Result + mCode[I];
              If mCode[I] = #10 Then J := 0;
              Inc(I);
            End Else Begin
              Result := Result + mCode[I];
              Inc(J);
              Inc(I);
            End;
        End;
    End; { QuotedPrintableDecode }
    Function EMailBase64Encode(mSource: String; mAddLine: Boolean = True): String;
    Var
      I, J: Integer;
      S: String;
    Begin
      Result := '';
      J := 0;
      For I := 0 To Length(mSource) Div 3 - 1 Do Begin
          S := Copy(mSource, I * 3 + 1, 3);
          Result := Result + cBase64[Ord(S[1]) Shr 2 + 1];
          Result := Result + cBase64[((Ord(S[1]) And $03) Shl 4) + (Ord(S[2]) Shr 4) + 1];
          Result := Result + cBase64[((Ord(S[2]) And $0F) Shl 2) + (Ord(S[3]) Shr 6) + 1];
          Result := Result + cBase64[Ord(S[3]) And $3F + 1];
          If mAddLine Then Begin
              Inc(J, 4);
              If J >= 76 Then Begin
                  Result := Result + #13#10;
                  J := 0;
                End;
            End;
        End;
      I := Length(mSource) Div 3;
      S := Copy(mSource, I * 3 + 1, 3);
      Case Length(S) Of
        1: Begin
            Result := Result + cBase64[Ord(S[1]) Shr 2 + 1];
            Result := Result + cBase64[(Ord(S[1]) And $03) Shl 4 + 1];
            Result := Result + cBase64[65];
            Result := Result + cBase64[65];
          End;
        2: Begin
            Result := Result + cBase64[Ord(S[1]) Shr 2 + 1];
            Result := Result + cBase64[((Ord(S[1]) And $03) Shl 4) + (Ord(S[2]) Shr 4) + 1];
            Result := Result + cBase64[(Ord(S[2]) And $0F) Shl 2 + 1];
            Result := Result + cBase64[65];
          End;
      End;
    End; { Base64Encode }Function EMailBase64Decode(mCode: String): String;
    Var
      I, L: Integer;
      S: String;
    Begin
      Result := '';
      L := Length(mCode);
      I := 1;
      While I <= L Do Begin
          If Pos(mCode[I], cBase64) > 0 Then Begin
              S := Copy(mCode, I, 4);
              If (Length(S) = 4) Then Begin
                  Result := Result + Chr((Pos(S[1], cBase64) - 1) Shl 2 +
                    (Pos(S[2], cBase64) - 1) Shr 4);
                  If S[3] <> cBase64[65] Then Begin
                      Result := Result + Chr(((Pos(S[2], cBase64) - 1) And $0F) Shl 4 +
                        (Pos(S[3], cBase64) - 1) Shr 2);
                      If S[4] <> cBase64[65] Then
                        Result := Result + Chr(((Pos(S[3], cBase64) - 1) And $03) Shl 6 +
                          (Pos(S[4], cBase64) - 1));
                    End;
                End;
              Inc(I, 4);
            End Else Inc(I);
        End;
    End; { Base64Decode }Function Find(SubStr, Str: String; IsEnd: Boolean = False): Integer;
    Var
      i: integer;
    Begin
      Result := 0;
      If IsEnd Then
        Begin
          For i := Length(Str) Downto 0 Do
            If Copy(Str, i, Length(SubStr)) = SubStr Then
              Begin
                Result := i;
                Break;
              End;
        End
      Else
        For i := 0 To Length(Str) Do
          If Copy(Str, i, Length(SubStr)) = SubStr Then
            Begin
              Result := i;
              Break;
            End;End;
    end.
    ////------------------------------------------------------------------------------
    ////Base64Decode
    ////------------------------------------------------------------------------------
    //function TMainForm.Base64Decode(strInput : string) : string;
    //var
    //strDecode : string;
    //posStart: Integer;
    //posEnd : Integer;
    //begin
    //while pos('=?gb2312?b?',lowercase(strInput)) > 0 do
    //begin
    //try
    //posStart := pos('=?gb2312?b?',lowercase(strInput));
    //posEnd := pos('?=',lowercase(strInput));
    //strDecode := strDecode + copy(strInput,1,posStart-1) + IdDeMIME.DecodeString(copy(strInput,posStart+11,posEnd-posStart-11));
    //strInput := copy(strInput,posEnd+2,length(strInput)-posEnd-1);
    //finally
    //Application.ProcessMessages;
    //end;
    //end;
    //strDecode := strDecode + strInput;
    //result := strDecode;
    //end;
    //
    ////------------------------------------------------------------------------------
    ////Base64Encode
    ////------------------------------------------------------------------------------
    //function TMainForm.Base64Encode(strInput : string) : string;
    //var
    //strEncode : string;
    //begin
    //strEncode := IdEnMIME.EncodeString(strInput);
    //result := strEncode;
    //end;
    //
    ////------------------------------------------------------------------------------
    Function GetTitle(Const Value: String): String;
    Var
      TempStr, sStr, eStr: String;
    Begin
      sStr := Copy(Value, 1, Pos('=?', Value) - 1);
      TempStr := Copy(Value, Pos('=?', Value) + 2, Length(Value));
      eStr := Copy(TempStr, Find('?=', TempStr, True) + 2, Length(TempStr));
      TempStr := Copy(TempStr, 1, Find('?=', TempStr, True) - 1);
      If Pos('?B?', TempStr) > 0 Then
        Begin
          TempStr := Copy(TempStr, Pos('?B?', TempStr) + 3, Length(TempStr));
          TempStr := Base64Decode(TempStr);
          Result := sStr + TempStr + eStr;
          Exit;
        End
      Else
        If Pos('?b?', TempStr) > 0 Then
        Begin
          TempStr := Copy(TempStr, Pos('?b?', TempStr) + 3, Length(TempStr));
          TempStr := Base64Decode(TempStr);
          Result := sStr + TempStr + eStr;
          Exit;
        End;
      If Pos('?Q?', TempStr) > 0 Then
        Begin
          TempStr := Copy(TempStr, Pos('?Q?', TempStr) + 3, Length(TempStr));
          TempStr := QuotedPrintableDecode(TempStr);
          Result := sStr + TempStr + eStr;
          Exit;
        End
      Else
        If Pos('?q?', TempStr) > 0 Then
        Begin
          TempStr := Copy(TempStr, Pos('?q?', TempStr) + 3, Length(TempStr));
          TempStr := QuotedPrintableDecode(TempStr);
          Result := sStr + TempStr + eStr;
          Exit;
        End;
      Result := Value;End;
      

  2.   

    其实是公司希望在上传一些文件后,可以发送邮件通知,因为我们都是使用OFFICE OUTLOOK,所以,只能够用OFFICE OUTLOOK