你怎么知道附件的数量?这是已知的预发送还是直到发送时间?这是触发发送还是用户启动?
根据这些答案,您可以通过多种方式实现这一目标。
我将探索的主要解决方案路径是执行某种 LookupRows() 或 LookupOrderedRows() 来检索要附加的文件,然后遍历这些行并附加文件。另外,需要注意的是 AttachFile() 函数需要在 inline-AMP Script 中执行,%%=AttachFile()=%%,而不是在 AMP 代码块中,%%[ ...... ]%%。
因此,您的代码可能类似于以下内容(我包含了托管在外部站点、ET FTP 和 Portfolio 上的文件示例):
%%[ VAR @sub, @fileDe, @files, @file, @fileUrl, @fileName, @fileExternalKey
SET @sub = [_subscriberkey]
SET @fileDE = "Name Data Extension holding attachment filename/url"
/*LookupRows() from DE. Assumes data extension uses SubscriberKey as the foreign key*/
SET @files = LookupRows(@fileDe,"SubscriberKey",@sub)
/*Validate files were returned*/
IF Rowcount(@files) > 0 THEN
FOR @i = 1 TO Rowcount(@files) DO
SET @file = Row(@files,@i)
/*If you are using files hosted at an external HTTP/HTTPS location*/
SET @fileUrl = Field(@file,"FileURL")
]%%
%%=AttachFile("HTTP",@fileUrl)=%%
%%[
/*If you are using files hosted in the Import folder of the ExactTarget FTP*/
SET @fileName = Field(@file,"FileName")
]%%
%%=AttachFile("FTP",@fileName)=%%
%%[
/*If you are using files hosted in the ExactTarget Portfolio*/
SET @fileName = Field(@file,"PortfolioFileExternalKey")
]%%
%%=AttachFile("Portfolio",@fileExternalKey)=%%
%%[
NEXT @i
ELSE
/*No records returned for @files*/
ENDIF
]%%