Delphi 发送邮件!

{拉2个控件下来IdSMTP1(在Indy Clients页面), IdMessage1(在Indy Misc页面)
 实现从XXOO@163.com邮箱发送带附件的邮件到10086@qq.com邮箱}

procedure TForm1.SendMail;
begin
  with IdSMTP1 do
  begin
    Host:='smtp.163.com';
    Port:=25;
    Username:='XXOO';
    Password:='13800138000';
    AuthenticationType:=atLogin;
  end;

  with IdMessage1 do
  begin
    MessageParts.Clear;
    Recipients.EMailAddresses:='10086@qq.com';
    From.address:='XXOO@163.com';
    Subject:='Hello';
    Body.Add('Hello World');
  end;

  TIdAttachment.Create(IdMessage1.MessageParts,'D:\1.xls');//添加附件

  try
  IdSMTP1.Connect;
  except on E: Exception do
    begin
      showmessage('连接服务嚣失败:'+E.Message);
      exit;
    end;
  end;

  try
  if IdSMTP1.Authenticate then  //如果AuthenticationType:=atNone; 把if IdSMTP1.Authenticate then去掉
  begin
    try
    IdSMTP1.Send(IdMessage1);
    except on E: Exception do
      begin
        showmessage('在发送过程中发生错误:'+E.Message);
        exit;
      end;
    end;

    showmessage('发送成功!');
  end;
  finally
    IdSMTP1.Disconnect;
  end;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值