2010发邮件附件收到乱码。解决方法
2010发邮件附件收到乱码。
发送可以,但接收的时候显示的不是附件,而是乱码。下面是邮件内容:
This is a multi-part message in MIME format --EpftIiTK2Nd9EQBt3=_VB0idgG2t5eaJAL Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Memo1 --EpftIiTK2Nd9EQBt3=_VB0idgG2t5eaJAL Content-Type: application/octet-stream; name="=?GB2312?B?PT9nYms/Qj8yLnR4dD89?=" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="=?GB2312?B?PT9nYms/Qj8yLnR4dD89?=" 1eLA78rHuL28/qOhDQoxMjM0NTY3ODkxMjM0NTY3ODkNCnRlc3QgYXR0YWNoDQqy4srUuL28/sTc srvE3MrVtb2how== --EpftIiTK2Nd9EQBt3=_VB0idgG2t5eaJAL--
要怎么样才能发送附件呢?
------解决方案--------------------
刚试了试,不用设置ba64;关键是你的IdMessage1的设置.我测试的例子
String filename = L"E:\\附件\\2.txt"; //需要添加的附件文件
IdMessage1-> MessageParts-> Add();
new TIdAttachmentFile(IdMessage1-> MessageParts,filename);
IdMessage1->MessageParts->Items[0]->FileName = L"=?gbk?B?" + ExtractFileName( filename) + L"?=";
发送可以,但接收的时候显示的不是附件,而是乱码。下面是邮件内容:
This is a multi-part message in MIME format --EpftIiTK2Nd9EQBt3=_VB0idgG2t5eaJAL Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Memo1 --EpftIiTK2Nd9EQBt3=_VB0idgG2t5eaJAL Content-Type: application/octet-stream; name="=?GB2312?B?PT9nYms/Qj8yLnR4dD89?=" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="=?GB2312?B?PT9nYms/Qj8yLnR4dD89?=" 1eLA78rHuL28/qOhDQoxMjM0NTY3ODkxMjM0NTY3ODkNCnRlc3QgYXR0YWNoDQqy4srUuL28/sTc srvE3MrVtb2how== --EpftIiTK2Nd9EQBt3=_VB0idgG2t5eaJAL--
要怎么样才能发送附件呢?
------解决方案--------------------
刚试了试,不用设置ba64;关键是你的IdMessage1的设置.我测试的例子
IdSMTP1->Username ="zzbinfo";
IdSMTP1->Password ="2629339zzb";
IdSMTP1->Host ="smtp.163.com";
IdSMTP1->Port =25;
IdMessage1->Body->Clear();
IdMessage1->Encoding = meMIME;
IdMessage1->ContentType = "multipart/alternative";//"text/html";
IdMessage1->ContentTransferEncoding="base64";
IdMessage1->CharSet="utf-8";
IdMessage1->Subject="测试";
IdMessage1->Body->Text ="This is a text!!!";
IdMessage1->From->Text="zzbinfo@163.com";
IdMessage1->Recipients->EMailAddresses="6171153@qq.com";
String filename = L"c:\\test.txt"; //需要添加的附件文件
IdMessage1-> MessageParts-> Add();
TIdAttachmentFile *AttachEmail = new TIdAttachmentFile(IdMessage1-> MessageParts,filename);
AttachEmail->ContentType="application/octet-stream";
AttachEmail->ContentDisposition="attachment";
AttachEmail->ContentTransfer="base64";
AttachEmail->FileName=ExtractFileName(filename);
try{
IdSMTP1->Connect();
IdSMTP1->Authenticate();
IdSMTP1->Send(IdMessage1);
}
catch(...)
{
ShowMessage("发送失败!");
return;
}
ShowMessage("发送成功!");
}