2016-06-10 106 views
0

我試圖獲取使用SES收到的電子郵件的內容。 但我得到的迴應是瘋狂獲取電子郵件內容AWS SES

{ 
    "notificationType": "Received", 
    "receipt": { 
     "timestamp": "2015-09-11T20:32:33.936Z", 
     "processingTimeMillis": 222, 
     "recipients": [ 
      "[email protected]" 
     ], 
     "spamVerdict": { 
      "status": "PASS" 
     }, 
     "virusVerdict": { 
      "status": "PASS" 
     }, 
     "spfVerdict": { 
      "status": "PASS" 
     }, 
     "dkimVerdict": { 
      "status": "PASS" 
     }, 
     "action": { 
      "type": "SNS", 
      "topicArn": "arn:aws:sns:us-east-1::example-topic" 
     } 
    }, 
    "mail": { 
     "timestamp": "2015-09-11T20:32:33.936Z", 
     "source": "[email protected]", 
     "messageId": "d6iitobk75ur44p8kdnnp7g2n800", 
     "destination": [ 
      "[email protected]" 
     ], 
     "headersTruncated": false, 
     "headers": [ 
      { 
       "name": "Return-Path", 
       "value": "<[email protected]zonses.com>" 
      }, 
      { 
       "name": "Received", 
       "value": "from a9-183.smtp-out.amazonses.com (a9-183.smtp-out.amazonses.com [54.240.9.183]) by inbound-smtp.us-east-1.amazonaws.com with SMTP id d6iitobk75ur44p8kdnnp7g2n800 for [email protected]; Fri, 11 Sep 2015 20:32:33 +0000 (UTC)" 
      }, 
      { 
       "name": "DKIM-Signature", 
       "value": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1442003552; h=From:To:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Message-ID:Feedback-ID; bh=DWr3IOmYWoXCA9ARqGC/UaODfghffiwFNRIb2Mckyt4=; b=p4ukUDSFqhqiub+zPR0DW1kp7oJZakrzupr6LBe6sUuvqpBkig56UzUwc29rFbJF hlX3Ov7DeYVNoN38stqwsF8ivcajXpQsXRC1cW9z8x875J041rClAjV7EGbLmudVpPX 4hHst1XPyX5wmgdHIhmUuh8oZKpVqGi6bHGzzf7g=" 
      }, 
      { 
       "name": "From", 
       "value": "[email protected]" 
      }, 
      { 
       "name": "To", 
       "value": "[email protected]" 
      }, 
      { 
       "name": "Subject", 
       "value": "Example subject" 
      }, 
      { 
       "name": "MIME-Version", 
       "value": "1.0" 
      }, 
      { 
       "name": "Content-Type", 
       "value": "text/plain; charset=UTF-8" 
      }, 
      { 
       "name": "Content-Transfer-Encoding", 
       "value": "7bit" 
      }, 
      { 
       "name": "Date", 
       "value": "Fri, 11 Sep 2015 20:32:32 +0000" 
      }, 
      { 
       "name": "Message-ID", 
       "value": "<[email protected]>" 
      }, 
      { 
       "name": "X-SES-Outgoing", 
       "value": "2015.09.11-54.240.9.183" 
      }, 
      { 
       "name": "Feedback-ID", 
       "value": "1.us-east-1.Krv2FKpFdWV+KUYw3Qd6wcpPJ4Sv/pOPpEPSHn2u2o4=:AmazonSES" 
      } 
     ], 
     "commonHeaders": { 
      "returnPath": "[email protected]zonses.com", 
      "from": [ 
       "[email protected]" 
      ], 
      "date": "Fri, 11 Sep 2015 20:32:32 +0000", 
      "to": [ 
       "[email protected]" 
      ], 
      "messageId": "<[email protected]>", 
      "subject": "Example subject" 
     } 
    }, 
    "content": "Return-Path: <[email protected]>\r\nReceived: from a9-183.smtp-out.amazonses.com (a9-183.smtp-out.amazonses.com [54.240.9.183])\r\n by inbound-smtp.us-east-1.amazonaws.com with SMTP id d6iitobk75ur44p8kdnnp7g2n800\r\n for [email protected];\r\n Fri, 11 Sep 2015 20:32:33 +0000 (UTC)\r\nDKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;\r\n\ts=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1442003552;\r\n\th=From:To:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Message-ID:Feedback-ID;\r\n\tbh=DWr3IOmYWoXCA9ARqGC/UaODfghffiwFNRIb2Mckyt4=;\r\n\tb=p4ukUDSFqhqiub+zPR0DW1kp7oJZakrzupr6LBe6sUuvqpBkig56UzUwc29rFbJF\r\n\thlX3Ov7DeYVNoN38stqwsF8ivcajXpQsXRC1cW9z8x875J041rClAjV7EGbLmudVpPX\r\n\t4hHst1XPyX5wmgdHIhmUuh8oZKpVqGi6bHGzzf7g=\r\nFrom: [email protected]\r\nTo: [email protected]\r\nSubject: Example subject\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: 7bit\r\nDate: Fri, 11 Sep 2015 20:32:32 +0000\r\nMessage-ID: <[email protected]>\r\nX-SES-Outgoing: 2015.09.11-54.240.9.183\r\nFeedback-ID: 1.us-east-1.Krv2FKpFdWV+KUYw3Qd6wcpPJ4Sv/pOPpEPSHn2u2o4=:AmazonSES\r\n\r\nExample content\r\n" 
} 

我可以輕鬆搞定的問題,但我不能相信該消息的內容是很難提取,內容爲Example content和唯一的地方,我可以找到它是在content的關鍵,但它很難解析

回答

2

是的!

作爲一個例子,如果您使用gmail或其他電子郵件客戶端,請查看您將看到的關於同一事物的原始數據或郵件來源(與JSON表示有所不同),但電子郵件的內容基於RFC2045

Contents of Notifications for Amazon SES Email Receiving被記錄在案,並從頂層JSON對象

內容:包含原始的,未經修改的電子郵件,這是 典型的多用途Internet郵件擴展字符串(MIME )格式。有關MIME格式 的更多信息,請參見RFC 2045

此字段只如果通知被 的SNS操作觸發。由所有其他操作觸發的通知不包含此字段的 。

0

該POJO可能幫助:

public class SESMessageData { 

public SESMessageData() { 
} 

private String notificationType; 

private Receipt receipt; 

private Mail mail; 

public String getNotificationType() { 
    return notificationType; 
} 

public void setNotificationType(String notificationType) { 
    this.notificationType = notificationType; 
} 

public Receipt getReceipt() { 
    return receipt; 
} 

public void setReceipt(Receipt receipt) { 
    this.receipt = receipt; 
} 

public Mail getMail() { 
    return mail; 
} 

public void setMail(Mail mail) { 
    this.mail = mail; 
} 

public static class Receipt { 

    private Action action; 

    private Verdict dkimVerdict; 

    private String processingTimeMillis; 

    private Verdict spamVerdict; 

    private Verdict spfVerdict; 

    private String timestamp; 

    private Verdict virusVerdict; 

    private List<String> recipients; 

    /** 
    * @return A list of the recipient addresses for this delivery. 
    */ 
    public List<String> getRecipients() { 
     return recipients; 
    } 

    public void setRecipients(List<String> recipients) { 
     this.recipients = recipients; 
    } 

    /** 
    * @return Object that encapsulates information about the action that was executed. 
    */ 
    public Action getAction() { 
     return action; 
    } 

    public void setAction(Action action) { 
     this.action = action; 
    } 

    /** 
    * @return Object that indicates whether the DomainKeys Identified Mail (DKIM) check passed. 
    */ 
    public Verdict getDkimVerdict() { 
     return dkimVerdict; 
    } 

    public void setDkimVerdict(Verdict dkimVerdict) { 
     this.dkimVerdict = dkimVerdict; 
    } 

    /** 
    * @return String that specifies the period, in milliseconds, from the time Amazon SES received the message to the time it triggered the action. 
    */ 
    public String getProcessingTimeMillis() { 
     return processingTimeMillis; 
    } 

    public void setProcessingTimeMillis(String processingTimeMillis) { 
     this.processingTimeMillis = processingTimeMillis; 
    } 

    /** 
    * @return Object that indicates whether the message is spam. 
    */ 
    public Verdict getSpamVerdict() { 
     return spamVerdict; 
    } 

    public void setSpamVerdict(Verdict spamVerdict) { 
     this.spamVerdict = spamVerdict; 
    } 

    /** 
    * @return Object that indicates whether the Sender Policy Framework (SPF) check passed. 
    */ 
    public Verdict getSpfVerdict() { 
     return spfVerdict; 
    } 

    public void setSpfVerdict(Verdict spfVerdict) { 
     this.spfVerdict = spfVerdict; 
    } 

    /** 
    * @return String that specifies when the action was triggered, in ISO8601 format. 
    */ 
    public String getTimestamp() { 
     return timestamp; 
    } 

    public void setTimestamp(String timestamp) { 
     this.timestamp = timestamp; 
    } 

    /** 
    * @return Object that indicates whether the message contains a virus. 
    */ 
    public Verdict getVirusVerdict() { 
     return virusVerdict; 
    } 

    public void setVirusVerdict(Verdict virusVerdict) { 
     this.virusVerdict = virusVerdict; 
    } 

    /** 
    * Object that encapsulates information about the action that was executed. 
    */ 
    public class Action { 
     private String type; 
     private String topicArn; 
     private String bucketName; 
     private String objectKey; 
     private String smtpReplyCode; 
     private String statusCode; 
     private String message; 
     private String sender; 
     private String functionArn; 
     private String invocationType; 
     private String organizationArn; 

     /** 
     * @return String that indicates the type of action that was executed. Possible values are S3, SNS, Bounce, Lambda, Stop, and WorkMail. 
     */ 
     public String getType() { 
      return type; 
     } 

     public void setType(String type) { 
      this.type = type; 
     } 

     /** 
     * @return String that contains the Amazon Resource Name (ARN) of the Amazon SNS topic to which the notification was published. 
     */ 
     public String getTopicArn() { 
      return topicArn; 
     } 

     public void setTopicArn(String topicArn) { 
      this.topicArn = topicArn; 
     } 

     /** 
     * @return String that contains the name of the Amazon S3 bucket to which the message was published. Present only for the S3 action type. 
     */ 
     public String getBucketName() { 
      return bucketName; 
     } 

     public void setBucketName(String bucketName) { 
      this.bucketName = bucketName; 
     } 

     /** 
     * @return String that contains a name that uniquely identifies the email in the Amazon S3 bucket. This is the same as the messageId in the mail object. Present only for the S3 action type. 
     */ 
     public String getObjectKey() { 
      return objectKey; 
     } 

     public void setObjectKey(String objectKey) { 
      this.objectKey = objectKey; 
     } 

     /** 
     * @return String that contains the SMTP reply code, as defined by RFC 5321. Present only for the bounce action type. 
     */ 
     public String getSmtpReplyCode() { 
      return smtpReplyCode; 
     } 

     public void setSmtpReplyCode(String smtpReplyCode) { 
      this.smtpReplyCode = smtpReplyCode; 
     } 

     /** 
     * @return String that contains the SMTP enhanced status code, as defined by RFC 3463. Present only for the bounce action type. 
     */ 
     public String getStatusCode() { 
      return statusCode; 
     } 

     public void setStatusCode(String statusCode) { 
      this.statusCode = statusCode; 
     } 

     public String getMessage() { 
      return message; 
     } 

     public void setMessage(String message) { 
      this.message = message; 
     } 

     public String getSender() { 
      return sender; 
     } 

     public void setSender(String sender) { 
      this.sender = sender; 
     } 

     public String getFunctionArn() { 
      return functionArn; 
     } 

     public void setFunctionArn(String functionArn) { 
      this.functionArn = functionArn; 
     } 

     public String getInvocationType() { 
      return invocationType; 
     } 

     public void setInvocationType(String invocationType) { 
      this.invocationType = invocationType; 
     } 

     public String getOrganizationArn() { 
      return organizationArn; 
     } 

     public void setOrganizationArn(String organizationArn) { 
      this.organizationArn = organizationArn; 
     } 

     @Override 
     public String toString() { 
      return "Action{" + 
        "type='" + type + '\'' + 
        ", topicArn='" + topicArn + '\'' + 
        ", bucketName='" + bucketName + '\'' + 
        ", objectKey='" + objectKey + '\'' + 
        ", smtpReplyCode='" + smtpReplyCode + '\'' + 
        ", statusCode='" + statusCode + '\'' + 
        ", message='" + message + '\'' + 
        ", sender='" + sender + '\'' + 
        ", functionArn='" + functionArn + '\'' + 
        ", invocationType='" + invocationType + '\'' + 
        ", organizationArn='" + organizationArn + '\'' + 
        '}'; 
     } 
    } 

    public class Verdict { 
     private String status; 

     public String getStatus() { 
      return status; 
     } 

     public void setStatus(String status) { 
      this.status = status; 
     } 

     @Override 
     public String toString() { 
      return "Verdict{" + 
        "status='" + status + '\'' + 
        '}'; 
     } 
    } 

    @Override 
    public String toString() { 
     return "Receipt{" + 
       "action=" + action + 
       ", dkimVerdict=" + dkimVerdict + 
       ", processingTimeMillis='" + processingTimeMillis + '\'' + 
       ", spamVerdict=" + spamVerdict + 
       ", spfVerdict=" + spfVerdict + 
       ", timestamp='" + timestamp + '\'' + 
       ", virusVerdict=" + virusVerdict + 
       ", recipients=" + recipients + 
       '}'; 
    } 
} 

public static class Mail { 

    private List<String> destination; 

    private String messageId; 

    private String source; 

    private String timestamp; 

    private List<Header> headers; 

    private CommonHeader commonHeaders; 

    private String headersTruncated; 

    /** 
    * @return A list of email addresses that are recipients of the email. 
    */ 
    public List<String> getDestination() { 
     return destination; 
    } 

    public void setDestination(List<String> destination) { 
     this.destination = destination; 
    } 

    public String getMessageId() { 
     return messageId; 
    } 

    public void setMessageId(String messageId) { 
     this.messageId = messageId; 
    } 

    public String getSource() { 
     return source; 
    } 

    public void setSource(String source) { 
     this.source = source; 
    } 

    public String getTimestamp() { 
     return timestamp; 
    } 

    public void setTimestamp(String timestamp) { 
     this.timestamp = timestamp; 
    } 

    public List<Header> getHeaders() { 
     return headers; 
    } 

    public void setHeaders(List<Header> headers) { 
     this.headers = headers; 
    } 

    public CommonHeader getCommonHeaders() { 
     return commonHeaders; 
    } 

    public void setCommonHeaders(CommonHeader commonHeaders) { 
     this.commonHeaders = commonHeaders; 
    } 

    public String getHeadersTruncated() { 
     return headersTruncated; 
    } 

    public void setHeadersTruncated(String headersTruncated) { 
     this.headersTruncated = headersTruncated; 
    } 

    public class Header { 

     private String name; 
     private String value; 

     public String getName() { 
      return name; 
     } 

     public void setName(String name) { 
      this.name = name; 
     } 

     public String getValue() { 
      return value; 
     } 

     public void setValue(String value) { 
      this.value = value; 
     } 

     @Override 
     public String toString() { 
      return "Header{" + 
        "name='" + name + '\'' + 
        ", value='" + value + '\'' + 
        '}'; 
     } 
    } 

    public class CommonHeader { 

     private String returnPath; 

     private List<String> from; 

     private List<String> to; 

     private String messageId; 

     private String subject; 

     public String getReturnPath() { 
      return returnPath; 
     } 

     public void setReturnPath(String returnPath) { 
      this.returnPath = returnPath; 
     } 

     public List<String> getFrom() { 
      return from; 
     } 

     public void setFrom(List<String> from) { 
      this.from = from; 
     } 

     public List<String> getTo() { 
      return to; 
     } 

     public void setTo(List<String> to) { 
      this.to = to; 
     } 

     public String getMessageId() { 
      return messageId; 
     } 

     public void setMessageId(String messageId) { 
      this.messageId = messageId; 
     } 

     public String getSubject() { 
      return subject; 
     } 

     public void setSubject(String subject) { 
      this.subject = subject; 
     } 

     @Override 
     public String toString() { 
      return "CommonHeader{" + 
        "returnPath='" + returnPath + '\'' + 
        ", from=" + from + 
        ", to=" + to + 
        ", messageId='" + messageId + '\'' + 
        ", subject='" + subject + '\'' + 
        '}'; 
     } 
    } 

    @Override 
    public String toString() { 
     return "Mail{" + 
       "destination=" + destination + 
       ", messageId='" + messageId + '\'' + 
       ", source='" + source + '\'' + 
       ", timestamp='" + timestamp + '\'' + 
       ", headers=" + headers + 
       ", commonHeaders=" + commonHeaders + 
       ", headersTruncated='" + headersTruncated + '\'' + 
       '}'; 
    } 
} 

@Override 
public String toString() { 
    return "SESMessageData{" + 
      "notificationType='" + notificationType + '\'' + 
      ", receipt=" + receipt + 
      ", mail=" + mail + 
      '}'; 
} 

}

相關問題