Delphi中发送邮件的代码,不完全参考

本文提供了一个使用Indy10组件发送电子邮件的示例代码,详细展示了如何设置SMTP服务器参数、邮件内容及附件,并介绍了批量发送邮件的方法。

 indy10组件的 发送邮件代码,不完全

[本文由iuprg 发表]

[http://www.newsoftstudio.com]

====================================

我的发送代码,仅供参考:

...
...
     SMTP.Username   := SmtpServerUser;
     SMTP.Password := SmtpServerpassword ;
     SMTP.Host := SmtpServerName;

     case   SmtpAuthType of
     0: SMTP.Authtype :=atdefault ;
     1:
       SMTP.Authtype :=atNone ;
     2:
       SMTP.Authtype :=atSASL ;
     end;

     SMTP.Port := SmtpServerPort;
  
   // 'IdMsgSend:tidMsgsend
   with IdMsgSend do

      begin
         Clear;

         Priority := TIdMessagePriority(mpNormal); { Message Priority }
         From.Address:= UserEmail;
     
         Subject := trim(dbeditex3.Text) ; { Subject: header }
         Recipients.EMailAddresses := trim(dbeditex1.Text) ; { To: header }

         Body.Clear;
         Body.Add(dbmemo1.Text);
        /// 附件 :
         for i:=0 to listview2.Items.Count -1 do
         begin
          TIdAttachmentFile.Create(IdMsgSend.MessageParts,
           listview2.Items[i].SubItems.Strings[1]);
          // 9.0版本 TIdAttachment.Create(IdMsgSend.MessageParts,
          // listview2.Items[i].SubItems.Strings[1]);
          //这里是indy 10组件
         end;
          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; // idsendmsg

    {authentication settings}

//[本文由iuprg 发表]

//[http://www.newsoftstudio.com]


  try

    if not smtp.Connected then
     SMTP.Connect;

     /// 开始批量发送
     if radiobutton2.Checked then
     begin
       gressbar(listview1.Items.Count,'正在发邮件...');

          IdMsgSend.Recipients.EMailAddresses :=
                listview1.Items[i].SubItems.strings[0];
          try
            if not smtp.Connected then
             SMTP.Connect;
             try
              SMTP.Send(IdMsgSend);
             finally
              smtp.Disconnect;
             end;  // 每次发送必须建立一次连接,因为 有的 mail系统会限制一次连接
                  // 只能发送 2封邮件,而会提示“too many letters during this connection”
          except 
             if showmess(2,1,'往'+listview1.Items[i].SubItems.strings[0]+'发送邮件不成功!请检查输入的邮件地址是否正确/网络连接是否正常,您要继续么?')=1 then
             begin
                 if  smtp.Connected then
                 SMTP.disConnect;
                 break;
             end;
           
          end;

          gresspos(i);

       self.Caption:='发送完毕';
       gressrelease;
     end;

     if  radiobutton1.Checked then
     begin
      gressbar(listview1.Items.Count,'正在发送邮件...');
     if smtp.Connected then
        SMTP.Send(IdMsgSend);

      gresspos(10);
      gressrelease;
     end;


       savemail('1');                     // 保存 邮件,    
  
   if  smtp.Connected then
       SMTP.Disconnect;


    speedbutton2.Enabled :=false;
    showmess(0,9,'邮件发送成功。');
  except

    datamd.adoq_mail.cancel;
     gressrelease;
    if  smtp.Connected then
       SMTP.Disconnect;
    showmess(2,9,'邮件发送不成功!');
  end 

[本文由iuprg 发表]

2006-7-2

[http://www.newsoftstudio.com]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安优小青和他的程序生活

感谢您的打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值