我们能够发送简单的电子邮件。但我们需要在 vc 6.0 中使用 smtp 发送带有文件附件的电子邮件。
bool SendMail()
{
if (!ValidateEnvelope(sendmail.host, sendmail.recip,
sendmail.sender, &sendmail.IP)) return false;
char tmp[255];
if (sendmail.sender=="" || sendmail.recip=="" ||
sendmail.body=="" || sendmail.subject=="") return false;
sendmail.hSocket=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sendmail.hSocket==SOCKET_ERROR) return false;
if (!ConnectTo())
{
printf("Unable to connect to the server.\n");
return false;
}
snd("HELO", true);
sprintf(tmp, "%s%s%s", "MAIL FROM:<", sendmail.sender, ">");
snd(tmp, true);
sprintf(tmp, "%s%s%s", "RCPT TO:<", sendmail.recip, ">");
snd(tmp, true);
sprintf(tmp, "%s%s%s", "MAIL FROM:<", sendmail.sender, ">");
snd(tmp, true);
sprintf(tmp, "%s%s%s", "RCPT TO:<", sendmail.recip, ">");
snd(tmp, true);
snd("DATA", true);
sprintf(tmp, "%s%s", "From: ", sendmail.sender);
snd(tmp, false);
sprintf(tmp, "%s%s", "To: ", sendmail.recip);
snd(tmp, false);
sprintf(tmp, "%s%s", "Subject: ", sendmail.subject);
snd(tmp, false);
snd("", false);
snd(sendmail.body ,false);
snd(".", true);
snd("NOOP", true);
snd("QUIT", true);
closesocket(sendmail.hSocket);
return true;
}
如何在上面的代码中附加文件。提前致谢。