在CF9中使用cfscript如何发送带附件的电子邮件?

4

如何使用cfscript执行以下操作?

<cfmail
   from="me@domain.com"
   to="you@domain.com"
   subject="Attachments">
   <cfmailparam name="Reply-To" value="me@domain.com">
   Some message goes here...
   <cfmailparam file="c:\files\readme.txt">
   <cfmailparam file="c:\files\logo.gif">
</cfmail>

使用下面的代码会出现“FUNCTION 声明中缺少函数关键字”的错误:
mail subject="Test Email" from="me@domain.com to="you@domain.com" server="localhost" {
    mailpart file="#ExpandPath('readme.txt')#";
}
1个回答

8
这是一个详细说明需要完成的步骤: http://simonbingham.posterous.com/sending-email-using-cfscript-in-coldfusion-9
// Create an instance of the mail object
mail=new mail();

// Set it's properties
mail.setSubject( "Sample Email" );
mail.setTo( "to@example.com" );
mail.setFrom( "from@example.com" );
mail.setCC( "cc@example.com" );
mail.setBCC( "bcc@example.com" );

// Add an attachment
mail.addParam( file="C:\foo.txt" );

// Add email body content in text and HTML formats
mail.addPart( type="text", charset="utf-8", wraptext="72", body="This is a test message." );
mail.addPart( type="html", charset="utf-8", body="<p>This is a test message.</p>" );

// Send the email
mail.send();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接