SalesForce电子邮件附件

时间:2013-09-17 11:18:45

标签: salesforce

使用SalesForce的发送电子邮件功能,它允许文件附件。我正在寻找一种方法将salesforce中的这个附件存储到发送电子邮件的对象。

我知道salesforce的这个限制

“附件未存储在从Salesforce发送的电子邮件中。要与电子邮件一起保存,附件必须先与电子邮件关联,或使用电子邮件转个案,电子邮件转换为Salesforce,发送给Salesforce,On -Demand Email-to-Case,或Saleforce for Outlook。“

有什么工作吗?

2 个答案:

答案 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. 我只在顶点代码中硬编码ToAddress,但您可以在VF页面中添加相同的内容。事实上,您可以提供与发送电子邮件相同的UI体验。
  2. 我没有尝试或执行上面给出的代码;请参考此作为参考,以了解Algo / flow。

答案 1 :(得分:0)

您是否研究过Salesforce For Outlook?它是Outlook的附加组件,它与Salesforce for Tasks,Meetings,Events,ECT同步。它还允许您通过单击按钮将电子邮件和附件保存到Salesforce中的帐户。我是700多名用户的唯一管理员,整个领域都使用它并喜欢它。