加急发送邮件,附件出现问题。

浩南_哥 2011-03-02 04:33:19
用TIdSMTP发送邮件,附带有附件,出现个很奇怪的问题,有的时候能够发送成功,有的时候发送不成功。
不成功是指邮件是发出去了,不过没有附件。(注:我发的邮件仅有附件没有正文的)

//我发的所有邮件都带附件没有正文,不成功的邮件正文里显示如下:
=?GB2312?B?MzI=?=
To: *****@sina.com
Content-Type: multipart/mixed;
boundary="=_NextPart_2rfkindysadvnqw3nerasdf";
charset="gb2312"
MIME-Version: 1.0
Date: Mon, 28 Feb 2011 13:17:31 +0800
X-Priority: 3
X-Library: Indy 9.00.10

This is a multi-part message in MIME format

--=_NextPart_2rfkindysadvnqw3nerasdf
Content-Type: text/plain
Content-Transfer-Encoding: 7bit


--=_NextPart_2rfkindysadvnqw3nerasdf
Content-Type: application/octet-stream;
name="A201102281317.xls"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="A201102281317.xls"

.......以下是一大堆字符 估计是附件的内容。

请各位高手帮忙解决下。
...全文
440 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wondyfox 2011-10-15
  • 打赏
  • 举报
回复
Attachment := TIdAttachment.Create(AMessage.MessageParts, AFile);
应该是用TIdAttachmentFile吧,不然连编译都过不去的
浩南_哥 2011-03-02
  • 打赏
  • 举报
回复
。。。。。错了 是回#2的问题。。
浩南_哥 2011-03-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kye_jufei 的回复:]
Delphi(Pascal) code
procedure TFormMain.SendMail(Recipient, Address: string);
const
sStars = 'BackgroundStars.jpg ';
var
AdressItem: TIdEMailAddressItem;
AFile: st……
[/Quote]

Attachment := TIdAttachment.Create(AMessage.MessageParts, AFile);
Attachment.ExtraHeaders.Values[ 'Content-ID '] := ' <PrettyPic> ';
Attachment.ContentType := 'image/jpeg ';
//Attachment.ContentType 如果是Excel文档应当怎么设置
//Attachment.ExtraHeaders.Values[ 'Content-ID ']

大侠请帮帮忙

另外:回#3 我发的邮件是Excel文档 都不超过1M的。
t8543 2011-03-02
  • 打赏
  • 举报
回复
檢查你的附件大小,有的郵件伺服器有大小限制的!
kye_jufei 2011-03-02
  • 打赏
  • 举报
回复
procedure   TFormMain.SendMail(Recipient,   Address:   string); 
const
sStars = 'BackgroundStars.jpg ';
var
AdressItem: TIdEMailAddressItem;
AFile: string;
AMessage: TIdMessage;
ASMTP: TIdSMTP;
AStream: TMemoryStream;
Attachment: TIdAttachment;
IdBody: TIdText;
IdHTML: TIdText;
idStars: TIdAttachment;
resStars: TStream;
TempFile: TStream;
begin
Screen.Cursor := crHourGlass;
AFile := FileListBox.FileName;
if FileExists(AFile) then begin
AMessage := TIdMessage.Create(nil);
AMessage.NoDecode := False;
AMessage.NoEncode := False;
AMessage.ContentType := 'multipart/mixed ';
AMessage.Encoding := meMIME;
AMessage.MsgId := 'PrettyPic ';
AMessage.References := ChangeFileExt(ExtractFileName(AFile), ' ');
// Set recipients.
AdressItem := AMessage.Recipients.Add;
AdressItem.Name := Recipient;
AdressItem.Address := Address;
// Set subject.
AMessage.Subject := 'Hello. ';
// Set sender.
AMessage.Sender.Name := 'Workshop Alex ';
AMessage.Sender.Address := 'someone@somewhere.org ';
// Set from.
AMessage.From.Name := AMessage.Sender.Name;
AMessage.From.Address := AMessage.Sender.Address;
// Create plain body.
IdBody := TIdText.Create(AMessage.MessageParts);
IdBody.ContentType := 'text/plain ';
IdBody.Body.Add( 'Hello, friends. ');
IdBody.Body.Add( ' ');
// Add more to the plain-text bodypart.
// Create HTML body.
IdHTML := TIdText.Create(AMessage.MessageParts);
IdHTML.ContentType := 'text/html; charset=US-ASCII ';
IdHTML.ContentTransfer := '7bit ';
IdHTML.Body.Add( ' <html> ');
IdHTML.Body.Add( ' <head> ');
IdHTML.Body.Add( ' <title> Hello </title> ');
IdHTML.Body.Add( ' </head> ');
IdHTML.Body.Add( ' <body title= " ' + AMessage.References + ' " background= "cid:BackgroundStars "> ');
IdHTML.Body.Add( ' Hello, friends. <br> ');
IdHTML.Body.Add( ' <br> ');
IdHTML.Body.Add( ' <img src= "cid:PrettyPic " alt= " ' + ExtractFileName(AFile) + ' " name= " ' + ExtractFileName(AFile) + ' " title= "Just an image included. "> ');
IdHTML.Body.Add( ' </body> ');
IdHTML.Body.Add( ' </html> ');
// Add the attachment. Don 't forget the extra headers!
Attachment := TIdAttachment.Create(AMessage.MessageParts, AFile);
Attachment.ExtraHeaders.Values[ 'Content-ID '] := ' <PrettyPic> ';
Attachment.ContentType := 'image/jpeg ';
idStars := TIdAttachment.Create(AMessage.MessageParts, ExtractFilePath(ParamStr(0)) + sStars);
idStars.ExtraHeaders.Values[ 'Content-ID '] := ' <BackgroundStars> ';
idStars.ContentType := 'image/jpeg ';
// Now send the thing...
ASMTP := TIdSMTP.Create(nil);
ASMTP.Host := 'mail.whatever.org ';
ASMTP.Port := 25;
ASMTP.AuthenticationType := atNone;
ASMTP.Connect;
try
ASMTP.Send(AMessage);
except
on E: Exception do ShowMessageFmt( 'Error: %s ', [E.Message]);
end;
ASMTP.Disconnect;
AMessage.Free;
ASMTP.Free;
end;
Screen.Cursor := crDefault;
end;

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧