代码如下: 
   mmo2.Text:=AqEmailSend.SendBody;  //mmo2.txt:='您好'   IdMsgSend.MessageParts.Clear;
   Terms:=TStringList.Create;
   SplitString(AqEmailSend.SendFiles,';',Terms);
   for i:=0 to terms.Count-1 do
     if Terms.Strings[i]<>'' then
       TIdAttachment.Create(IdMsgSend.MessageParts,Terms.Strings[i]);
   Terms.Free; //Terms.Strings[0]:='C:/1.txt');   while not qryExeCrm.Eof do
   begin
     with IdMsgSend do
     begin
       Body.Assign(mmo2.Lines);
       From.Text :=AqEmailPars.UserEmail;
       //AqEmailPars.UserEmail:='[email protected]';       ReplyTo.EMailAddresses :='[email protected]';
       Recipients.EMailAddresses :='[email protected]';
       //Recipients.EMailAddresses:='[email protected]';   
       Subject := AqEmailSend.SendSubject;
        AqEmailSend.SendSubject:=发送邮件主题'
       Priority := TIdMessagePriority(2);//Normal 
       ReceiptRecipient.Text := '';
     end;     case AqEmailPars.SmtpAuthType of
        0: SMTP.AuthenticationType := atNone;
        1: SMTP.AuthenticationType := atLogin;
     end;     SMTP.Username := AqEmailPars.SmtpServerUser;
     SMTP.Password := AqEmailPars.SmtpServerPassword;
     SMTP.Host := AqEmailPars.SmtpServerName;
     SMTP.Port := AqEmailPars.SmtpServerPort;     SMTP.Connect;//通过
     try
        SMTP.Send(IdMsgSend);//通过
     finally
        SMTP.Disconnect;
     end;
     qryExeCrm.Edit;
     qryExeCrm.FieldByName('F_SendDate').AsString:=FormatDateTime('YYYY-MM-DD',Now);
     qryExeCrm.FieldByName('F_Status').AsString:='已发送';
     qryExeCrm.Post;
     qryExeCrm.Next;
     非常正常地结束
  end;
这段代码直接拷贝于Indy 9.0的Demo.稍微修改.  
一开始成功过(发送邮件正文和附件都很正常),当然不确认后来是否修改(检查很多次就是检查不出来),后来发现发送的附件收到后变成放在正文里的乱码(类似base64编码).于是便修改
也不知道把哪里修错了,后来就导致发后,邮件都收不到.(发送很正常完成,病毒防护软件也检测到邮件发送,可就是收不到.我用foxmail同样发了,可能收.说明邮箱是没问题的.)拜托大家看看.

解决方案 »

  1.   

    我知道了 ,竟然发送的body和subject不能为数字或中文??? 靠
      

  2.   

    此代码发送后收不到:
      
    mmo2.Text:='z阿瑟毒发';
      with IdMsgSend do
      begin
        ContentType:='text/html';
        Body.Assign(mmo2.Lines);
        From.Text :='[email protected]';
        ReplyTo.EMailAddresses :='[email protected]';
        Recipients.EMailAddresses :='[email protected]';
        Subject := 'zz阿瑟毒发';
        Priority := TIdMessagePriority(2);//Normal
        ReceiptRecipient.Text := '';
      end;     SMTP.AuthenticationType := atLogin;     SMTP.Username := AqEmailPars.SmtpServerUser;
         SMTP.Password := AqEmailPars.SmtpServerPassword;
         SMTP.Host := AqEmailPars.SmtpServerName;
         SMTP.Port := AqEmailPars.SmtpServerPort;     //btnAqManSend.Enabled:=False;
         SMTP.Connect;//通过
         try
            SMTP.Send(IdMsgSend);//通过
         finally
            SMTP.Disconnect;
            //btnAqManSend.Enabled:=True;
         end;把mmo2.Text:='asdfasdf'; 和 Subject := 'zsdfsdfsaf';后却能很正常收到?? 怎么办?
      

  3.   

    with IdMsgSend do
      begin
        Body.Assign(Memo1.Lines);
        From.Text := UserEmail;
        Recipients.EMailAddresses := edtTo.Text; { To: header }
        Subject := edtSubject.Text; { Subject: header }
        Priority := TIdMessagePriority(cboPriority.ItemIndex); { Message Priority }
        CCList.EMailAddresses := edtCC.Text; {CC}
        BccList.EMailAddresses := edtBCC.Text; {BBC}
        if chkReturnReciept.Checked then
        begin {We set the recipient to the From E-Mail address }
          ReceiptRecipient.Text := From.Text;
        end
        else
        begin {indicate that there is no receipt recipiant}
          ReceiptRecipient.Text := '';
        end;
      end;  {authentication settings}
      case SmtpAuthType of
        0: SMTP.AuthenticationType := atNone;
        1: SMTP.AuthenticationType := atLogin; {Simple Login}
      end;
      SMTP.UserID := Trim(SmtpServerUser);
      SMTP.Password := SmtpServerPassword;
      {General setup}
      SMTP.Host := SmtpServerName;
      SMTP.Port := SmtpServerPort;
      {now we send the message}
      {SMTP.UserID := '1285189390';
      SMTP.Password := '123456';
      SMTP.Host := 'smtp.163.com';
      SMTP.Port := 25; }  {now we send the message}  try
        SMTP.Connect;
        try
          SMTP.Send(IdMsgSend);
          MessageDlg('邮件发送成功.',mtInformation, [mbYes], 0)   ;
        except
          MessageDlg('邮件发送失败,请检查SMTP设置.',mtError, [mbYes], 0)   ;
        end;
      finally
        SMTP.Disconnect;
      end;
    --------------------------------
    这是我用过的代码,一点问题都没有。