使用SalesForce的发送电子邮件功能,它允许文件附件。我正在寻找一种方法将salesforce中的这个附件存储到发送电子邮件的对象。
我知道salesforce的这个限制
“附件未存储在从Salesforce发送的电子邮件中。要与电子邮件一起保存,附件必须先与电子邮件关联,或使用电子邮件转个案,电子邮件转换为Salesforce,发送给Salesforce,On -Demand Email-to-Case,或Saleforce for Outlook。“
有什么工作吗?
答案 0 :(得分:1)
一个选项可以是使用Apex代码在Object的Attachment对象中上传它,然后发送电子邮件。
//Code for attaching a file from Local Machine
//VF Page
<apex:page controller="AttachmentUploadController">
<apex:sectionHeader title="Visualforce Example" subtitle="Attachment Upload Example"/>
<apex:form enctype="multipart/form-data">
<apex:pageMessages />
<apex:pageBlock title="Upload a Attachment">
<apex:pageBlockSection showHeader="false" columns="2" id="block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="File" for="file"/>
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:commandButton action="{!upload}" value="Upload and send an Email"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
//Controller
public with sharing class AttachmentUploadController
{
public Attachment attachment
{
get
{
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public PageReference upload()
{
String parentId = System.currentPagereference().getParameters().get('pid');
attachment.OwnerId = UserInfo.getUserId();
attachment.ParentId = parentId;
attachment.IsPrivate = true;
try
{
insert attachment;
//Start: Send Email with Attachment
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{<<email IDs>>};
mail.setToAddresses(toAddresses);
//Set email file attachments
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
// Add to attachment file list
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(attachment.Name);
efa.setBody(attachment.Body);
fileAttachments.add(efa);
//create attachment for object
Attachment att = new Attachment(name = attachment.name, body = attachment.body, parentid = Trigger.new[0].id);
insertAttList.add(att);
mail.setFileAttachments(fileAttachments);
//Send email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
//END : Send Email with Attachment
PageReference page = new PageReference('/' + parentId);
return page;
}
catch (DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,system.Label.Error_uploading_attachment));
return null;
}
finally
{
attachment = new Attachment();
}
}
}
注意事项:
答案 1 :(得分:0)
您是否研究过Salesforce For Outlook?它是Outlook的附加组件,它与Salesforce for Tasks,Meetings,Events,ECT同步。它还允许您通过单击按钮将电子邮件和附件保存到Salesforce中的帐户。我是700多名用户的唯一管理员,整个领域都使用它并喜欢它。