BCB中的发送邮件的例子

来自csdn的

 OnlyUx()

//--------------传到指定的邮箱------------------------
void __fastcall TfrmMain::SpeedButton1Click(TObject *Sender)
{
try
{  //::Sleep(100);
  Label2->Caption="正在登录服务器";
  IdMessage1->Recipients->EMailAddresses = "name1@163.com";     //邮件接收者的信箱
  IdMessage1->From->Text = "name2@sina.com";                    //邮件发送者的信箱
  IdMessage1->Subject =Memo1->Text;                             //邮件的标题
  IdMessage1->Body->Assign(Memo1->Lines);                       // 邮件的内容
if (IdSMTP1->Connected())
 {
    IdSMTP1->Disconnect();
 }
  IdSMTP1->AuthenticationType = atLogin; //登录服务器类型选择
  IdSMTP1->Host = "smtp.sina.com.cn";       //SMTP服务器
  IdSMTP1->UserId = "name2";              //邮箱的用户名
  IdSMTP1->Password = "name2@sina.com的密码";         //邮箱的密码
  IdSMTP1->Port = 25;                                        //端口
  IdSMTP1->Connect();                                      //连接SMTP服务器
  if (IdSMTP1->Authenticate())                         //用户验证
  {
    Label2->Caption="登录服务器验证成功";
    IdSMTP1->Send(IdMessage1);                   //发送邮件
    Label2->Caption="IP成功发送至name1@163.com";
  }

  IdSMTP1->Disconnect();
 }
 catch(...)
  {
  MessageBoxA(Handle,"请不要频繁发送","信息",0);
  return;
  }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值