怎样用API函数发送邮件及附件而不用VCL? 一点也不用VCL?那你最好别用Delphi了,用ASP什么的弄个脚本就行了:p 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 pdsinfo,你到底懂不懂啊?用WINSOCK直接发邮件我会,就是不知附件怎么发 在procedure TfrmMain.lvMessagePartsClick(Sender: TObject);里面:TIdAttachment(Msg.MessageParts.Items[i]).SaveToFile(SaveDialog1.FileName); WSADATA wsa; CString res,str; WSAStartup(0x0101,&wsa); struct sockaddr_in addr; SOCKET s; struct hostent* p=gethostbyname(smtp.etang.com);//prase Domain to IP if(!p){ pc->m_status+="\r\nError get IP."; pc->GetDlgItem(IDC_STATUS)->SetWindowText(pc->m_status); goto out; } s=socket(AF_INET,SOCK_STREAM,0); addr.sin_family=AF_INET; addr.sin_port=htons(25); addr.sin_addr.s_addr = *(unsigned long*)p->h_addr; if(connect(s,(struct sockaddr*)&addr,sizeof(addr))==SOCKET_ERROR){ pc->m_status+="\r\nError in connect to smtp server."; goto out; } str="HELO "+pc->m_Server+"\r\n";//Say HELLO to SMTP Server. if(send(s,(LPCSTR)str,str.GetLength(),0)==SOCKET_ERROR){ pc->m_status+="\r\nError in send HELO command."; goto out; } recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0); pc->m_status+="\r\n"+res; str="MAIL From: <"[email protected]+">\r\n";//Tell the sender of this mail. if(send(s,(LPCSTR)str,str.GetLength(),0)==SOCKET_ERROR){ pc->m_status+="\r\nError in MAIL FROM command"; goto out; } res.Empty(); recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0); pc->m_status+="\r\n"+res; str="RCPT TO: <"+pc->m_To+">\r\n";// if(send(s,(LPCSTR)str,str.GetLength(),0)==SOCKET_ERROR){ pc->m_status+="\r\nError in RCPT TO command"; //pc->GetDlgItem(IDC_STATUS)->SetWindowText(pc->m_status); goto out; } res.Empty(); recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0); pc->m_status+="\r\n"+res; str="DATA\r\n";//Start to transfer mail body. if(send(s,(LPCSTR)str,str.GetLength(),0)==SOCKET_ERROR){ pc->m_status+="\r\nError in DATA command"; goto out; } res.Empty(); recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0); pc->m_status+="\r\n"+res; if(send(s,(LPCSTR)pc->m_Content,pc->m_Content.GetLength(),0)==SOCKET_ERROR){ pc->m_status+="\r\nError in send mail body"; goto out; } res.Empty(); recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0); pc->m_status+="\r\n"+res; send(s,"\r\n.\r\n",5,0); str="VRFY "+pc->m_query+"\r\n"; send(s,str,str.GetLength(),0); res.Empty(); recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0); res="HELP"; send(s,res.GetBuffer(res.GetLength()),res.GetLength(),0); res.Empty(); recv(s,res.GetBufferSetLength(300),300,0); send(s,"QUIT\r\n",6,0); closesocket(s); WSACleanup(); out: pc->GetDlgItem(IDC_BTNSTOP)->EnableWindow(FALSE); pc->GetDlgItem(IDC_BTNSEND)->EnableWindow(TRUE); 不好意思,发错了。这个问题好像应该可以用ShellExecute(……,mailto:……)具体请看http://msdn.microsoft.com/library/en-us/dnfoxtk00/html/ft00h12.asp?frame=true 本机上的ORCALE数据库有没有办法自动更新 关于差异取屏的问题 简单的存储过程 摸拟点击的问题 idmessage 中如何設置才能在outlook中顯示收件人而不是一串mail地址(急) 用memo预览带有密码的word问题 图片问题 大家谁有解决ADO控件在使用时报错“BOF或EOF中有一个为真的解决方法吗?分不敢还可加 label怎样加方框?我知道static text可以!二者怎样纵向显示? 为什么进行Table删除后无法Post? 请问各位大侠李维什么时候到南京演讲 如何判断一个文件夹中是否有文件存在?若有文件如果将其名字列出?
用WINSOCK直接发邮件我会,就是不知附件怎么发
里面:
TIdAttachment(Msg.MessageParts.Items[i]).SaveToFile(SaveDialog1.FileName);
CString res,str;
WSAStartup(0x0101,&wsa);
struct sockaddr_in addr;
SOCKET s;
struct hostent* p=gethostbyname(smtp.etang.com);//prase Domain to IP
if(!p){
pc->m_status+="\r\nError get IP.";
pc->GetDlgItem(IDC_STATUS)->SetWindowText(pc->m_status);
goto out;
}
s=socket(AF_INET,SOCK_STREAM,0);
addr.sin_family=AF_INET;
addr.sin_port=htons(25);
addr.sin_addr.s_addr = *(unsigned long*)p->h_addr;
if(connect(s,(struct sockaddr*)&addr,sizeof(addr))==SOCKET_ERROR){
pc->m_status+="\r\nError in connect to smtp server.";
goto out;
}
str="HELO "+pc->m_Server+"\r\n";//Say HELLO to SMTP Server.
if(send(s,(LPCSTR)str,str.GetLength(),0)==SOCKET_ERROR){
pc->m_status+="\r\nError in send HELO command.";
goto out;
} recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0);
pc->m_status+="\r\n"+res;
str="MAIL From: <"[email protected]+">\r\n";//Tell the sender of this mail.
if(send(s,(LPCSTR)str,str.GetLength(),0)==SOCKET_ERROR){
pc->m_status+="\r\nError in MAIL FROM command";
goto out;
}
res.Empty();
recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0);
pc->m_status+="\r\n"+res;
str="RCPT TO: <"+pc->m_To+">\r\n";//
if(send(s,(LPCSTR)str,str.GetLength(),0)==SOCKET_ERROR){
pc->m_status+="\r\nError in RCPT TO command";
//pc->GetDlgItem(IDC_STATUS)->SetWindowText(pc->m_status);
goto out;
}
res.Empty();
recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0);
pc->m_status+="\r\n"+res;
str="DATA\r\n";//Start to transfer mail body.
if(send(s,(LPCSTR)str,str.GetLength(),0)==SOCKET_ERROR){
pc->m_status+="\r\nError in DATA command";
goto out;
}
res.Empty();
recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0);
pc->m_status+="\r\n"+res;
if(send(s,(LPCSTR)pc->m_Content,pc->m_Content.GetLength(),0)==SOCKET_ERROR){
pc->m_status+="\r\nError in send mail body";
goto out;
} res.Empty();
recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0);
pc->m_status+="\r\n"+res;
send(s,"\r\n.\r\n",5,0);
str="VRFY "+pc->m_query+"\r\n";
send(s,str,str.GetLength(),0);
res.Empty();
recv(s,res.GetBufferSetLength(INFOLEN),INFOLEN,0);
res="HELP";
send(s,res.GetBuffer(res.GetLength()),res.GetLength(),0);
res.Empty();
recv(s,res.GetBufferSetLength(300),300,0); send(s,"QUIT\r\n",6,0);
closesocket(s);
WSACleanup(); out:
pc->GetDlgItem(IDC_BTNSTOP)->EnableWindow(FALSE);
pc->GetDlgItem(IDC_BTNSEND)->EnableWindow(TRUE);
这个问题好像应该可以用ShellExecute(……,mailto:……)
具体请看
http://msdn.microsoft.com/library/en-us/dnfoxtk00/html/ft00h12.asp?frame=true