Java 我无法向带有字段定位器的收件人发送电子邮件

Java 我无法向带有字段定位器的收件人发送电子邮件,java,docusignapi,Java,Docusignapi,我无法发送电子邮件,我已尝试使用我的真实电子邮件,但尚未收到任何电子邮件。我怎样才能让它工作?我没有得到任何错误 Docusign没有一个干净的java示例,说明如何发送带有字段定位器的PDF文件,以便收件人签名。我从Docusign获得了以下示例代码: // Enter your DocuSign credentials String UserName = "myUserName@hotmail.com"; String Password = "

我无法发送电子邮件,我已尝试使用我的真实电子邮件,但尚未收到任何电子邮件。我怎样才能让它工作?我没有得到任何错误

Docusign没有一个干净的java示例,说明如何发送带有字段定位器的PDF文件,以便收件人签名。我从Docusign获得了以下示例代码:

        // Enter your DocuSign credentials
        String UserName = "myUserName@hotmail.com";
        String Password = "MyPassword";    
        String IntegratorKey = "c8ad614b-def7-4631-aede-c90e68ef84d4";

        // specify a document we want signed
        String SignTest1File = "C:/Users/Public/test/TEST.PDF";

        // enter recipient (signer) name and email
        String recipientName = "Recipient Name";
        String recipientEmail = "RecipientEmail@yahoo.com";     

        // for production environment update to "www.docusign.net/restapi"
        String BaseUrl = "https://demo.docusign.net/restapi";

        // initialize the api client for the desired environment
        ApiClient apiClient = new ApiClient();
        apiClient.setBasePath(BaseUrl);

        // create JSON formatted auth header
        String creds = "{\"Username\":\"" +  UserName + "\",\"Password\":\"" +  Password + "\",\"IntegratorKey\":\"" +  IntegratorKey + "\"}";
        apiClient.addDefaultHeader("X-DocuSign-Authentication", creds);

        // assign api client to the Configuration object
        Configuration.setDefaultApiClient(apiClient);

        // create an empty list that we will populate with accounts
        List<LoginAccount> loginAccounts = null;

        try
        {
            // login call available off the AuthenticationApi
            AuthenticationApi authApi = new AuthenticationApi();

            // login has some optional parameters we can set
            AuthenticationApi.LoginOptions loginOps = authApi.new LoginOptions();
            loginOps.setApiPassword("true");
            loginOps.setIncludeAccountIdGuid("true");
            LoginInformation loginInfo = authApi.login(loginOps);

            // note that a given user may be a member of multiple accounts
            loginAccounts = loginInfo.getLoginAccounts();

            System.out.println("LoginInformation: " + loginAccounts);
        }
        catch (com.docusign.esign.client.ApiException ex)
        {
            System.out.println("Exception: " + ex);
        }

        // create a byte array that will hold our document bytes
        byte[] fileBytes = null;

        try
        {
            //String currentDir = System.getProperty("user.dir");
            // read file from a local directory
            //Path path = Paths.get(currentDir + SignTest1File);
            Path path = Paths.get(SignTest1File);
            fileBytes = Files.readAllBytes(path);
        }
        catch (IOException ioExcp)
        {
            // handle error
            System.out.println("Exception: " + ioExcp);
            return;
        }

        // create an envelope that will store the document(s), tabs(s), and recipient(s)
        EnvelopeDefinition envDef = new EnvelopeDefinition();
        envDef.setEmailSubject("[Java SDK] - Please sign this doc");

        // add a document to the envelope
        Document doc = new Document();  
        String base64Doc = Base64.getEncoder().encodeToString(fileBytes);
        doc.setDocumentBase64(base64Doc);
        doc.setName("TestFile.pdf");    // can be different from actual file name
        doc.setDocumentId("1");

        List<Document> docs = new ArrayList<Document>();
        docs.add(doc);
        envDef.setDocuments(docs);

        // add a recipient to sign the document, identified by name and email we used above
        Signer signer = new Signer();
        signer.setName(recipientName);  
        signer.setEmail(recipientEmail);
        signer.setRecipientId("1");

        // to embed the recipient you must set their |clientUserId| property!
        signer.setClientUserId("1234");

        // create a signHere tab somewhere on the document for the signer to sign
        // default unit of measurement is pixels, can be mms, cms, inches also
        SignHere signHere = new SignHere();
        signHere.setDocumentId("1");
        signHere.setPageNumber("1");
        signHere.setRecipientId("1");
        signHere.setXPosition("100");
        signHere.setYPosition("150");

        // can have multiple tabs, so need to add to envelope as a single element list
        List<SignHere> signHereTabs = new ArrayList<SignHere>();      
        signHereTabs.add(signHere);
        Tabs tabs = new Tabs();
        tabs.setSignHereTabs(signHereTabs);
        signer.setTabs(tabs);

        // add recipients (in this case a single signer) to the envelope
        envDef.setRecipients(new Recipients());
        envDef.getRecipients().setSigners(new ArrayList<Signer>());
        envDef.getRecipients().getSigners().add(signer);

        // send the envelope by setting |status| to "sent". To save as a draft set to "created"
        envDef.setStatus("sent");

        // accountId is needed to create the envelope and for requesting the signer view
        String accountId = null;
        String envelopeId = null;

        try
        {
            // use the |accountId| we retrieved through the Login API to create the Envelope
            accountId = loginAccounts.get(0).getAccountId();

            // instantiate a new EnvelopesApi object
            EnvelopesApi envelopesApi = new EnvelopesApi();

            // call the createEnvelope() API to send the signature request!
            EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envDef);

            // save the |envelopeId| that was generated and use in next API call
            envelopeId = envelopeSummary.getEnvelopeId();

            System.out.println("EnvelopeSummary: " + envelopeSummary);
        }
        catch (com.docusign.esign.client.ApiException ex)
        {
            System.out.println("Exception: " + ex);
        }

        // use the |accountId| we retrieved through the Login API and the |envelopeId| that was generated during envelope creation
        accountId = loginAccounts.get(0).getAccountId();

        // instantiate a new EnvelopesApi object
        EnvelopesApi envelopesApi = new EnvelopesApi();

        // set the url where you want the recipient to go once they are done signing
        RecipientViewRequest returnUrl = new RecipientViewRequest();
        returnUrl.setReturnUrl("https://www.docusign.com/devcenter");
        returnUrl.setAuthenticationMethod("email");

        // recipient information must match embedded recipient info we provided in step #2
        returnUrl.setUserName(recipientName);
        returnUrl.setEmail(recipientEmail);
        returnUrl.setRecipientId("1");
        returnUrl.setClientUserId("1234");

        try 
        {
            // call the CreateRecipientView API then navigate to the URL to start the signing session
            ViewUrl recipientView = envelopesApi.createRecipientView(accountId, envelopeId, returnUrl);

            System.out.println("ViewUrl: " + recipientView);
        }
        catch (com.docusign.esign.client.ApiException ex)
        {
            System.out.println("Exception: " + ex);
        }       
//输入您的DocuSign凭据
字符串用户名=”myUserName@hotmail.com";
字符串Password=“MyPassword”;
字符串积分器key=“c8ad614b-def7-4631-aede-c90e68ef84d4”;
//指定要签名的文档
String SignTest1File=“C:/Users/Public/test/test.PDF”;
//输入收件人(签名人)姓名和电子邮件
字符串recipientName=“收件人名称”;
字符串recipientEmail=”RecipientEmail@yahoo.com";     
//将生产环境更新为“www.docusign.net/restapi”
字符串BaseUrl=”https://demo.docusign.net/restapi";
//为所需环境初始化api客户端
ApiClient ApiClient=新的ApiClient();
apiClient.setBasePath(BaseUrl);
//创建JSON格式的auth头
字符串creds=“{\'Username\”:\”+用户名+“\”,\“密码\”:\”+密码+“\”,\“积分器键\:\”+积分器键+“\”}”;
apiClient.addDefaultHeader(“X-DocuSign-Authentication”,creds);
//将api客户端分配给配置对象
setDefaultApiClient(apiClient);
//创建一个空列表,我们将用帐户填充该列表
列表loginAccounts=null;
尝试
{
//可通过AuthenticationApi进行登录调用
AuthenticationApi authApi=新的AuthenticationApi();
//登录有一些可选参数,我们可以设置
AuthenticationApi.LoginOptions loginOps=authApi.new LoginOptions();
loginOps.setApiPassword(“真”);
loginOps.setIncludeAccountdGuid(“真”);
LoginInformation loginInfo=authApi.login(loginOps);
//请注意,给定用户可能是多个帐户的成员
loginAccounts=loginInfo.getLoginAccounts();
System.out.println(“LoginInformation:+loginAccounts”);
}
catch(com.docusign.esign.client.ApiException)
{
System.out.println(“异常:+ex”);
}
//创建一个字节数组,用于保存文档字节
byte[]fileBytes=null;
尝试
{
//字符串currentDir=System.getProperty(“user.dir”);
//从本地目录读取文件
//Path Path=Path.get(currentDir+SignTest1File);
Path Path=Path.get(SignTest1File);
fileBytes=Files.readAllBytes(路径);
}
捕获(IOException ioExcp)
{
//处理错误
System.out.println(“异常:+ioExcp”);
返回;
}
//创建用于存储文档、选项卡和收件人的信封
EnvelopedDefinition envDef=新的EnvelopedDefinition();
envDef.setEmailSubject(“[Java SDK]-请签署此文件”);
//将文档添加到信封中
单据单据=新单据();
字符串base64Doc=Base64.getEncoder().encodeToString(fileBytes);
文件setDocumentBase64(base64Doc);
doc.setName(“TestFile.pdf”);//可以与实际文件名不同
文件setDocumentId(“1”);
列表文档=新建ArrayList();
docs.add(doc);
环境定义文件(文件);
//添加一个收件人来签署我们上面使用的名称和电子邮件标识的文档
签名者签名者=新签名者();
signer.setName(接收方名称);
signer.setEmail(recipientEmail);
签名人setRecipientId(“1”);
//要嵌入收件人,必须设置其| clientUserId |属性!
signer.setClientUserId(“1234”);
//在文档的某个位置创建signHere选项卡,供签名者签名
//默认测量单位为像素,也可以是彩信、cms、英寸
SignHere SignHere=新的SignHere();
signHere.setDocumentId(“1”);
signHere.setPageNumber(“1”);
signHere.setRecipientId(“1”);
signHere.setXPosition(“100”);
在此处签名。设置位置(“150”);
//可以有多个选项卡,因此需要将其作为单个元素列表添加到信封中
List signHereTabs=new ArrayList();
signHereTabs.add(signHere);
制表符=新制表符();
tabs.setSignHereTabs(signHereTabs);
签名者。设置选项卡(选项卡);
//将收件人(在本例中为单个签名者)添加到信封中
setRecipients(新收件人());
envDef.getRecipients().setSigners(新ArrayList());
envDef.getRecipients().getSigners().add(签名者);
//通过将“状态”设置为“已发送”发送信封。保存为草稿集的步骤设置为“已创建”
环境定义设置状态(“已发送”);
//创建信封和请求签名者视图需要accountId
字符串accountId=null;
字符串envelopeId=null;
尝试
{
//使用我们通过登录API检索到的| accountId |创建信封
accountId=loginAccounts.get(0.getAccountId();
//实例化一个新的EnvelopesApi对象
EnvelopesApi EnvelopesApi=新的EnvelopesApi();
//调用createEnvelope()API发送签名请求!
EnvelopesSummary EnvelopesSummary=envelopesApi.createEnvelope(accountId,envDef);
//保存生成的|信封ID |,并在下一个API调用中使用
envelopeId=EnvelopesSummary.getEnvelopeId();
System.out.println(“信封摘要:+信封摘要”);
}
catch(com.docusign.esign.client.ApiException)
{
System.out.println(“异常:+ex)
signer.setClientUserId("1234");