1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
{% extends "base.html" %}
{% block title %}{{ application_name }} Development Console - Inbound Mail{% endblock %}
{% block breadcrumbs %}
<span class="item"><a href="">Email</a></span>
{% endblock %}
{% block head %}
<style type="text/css">{% include "css/inboundmail.css" %}</style>
<script type="text/javascript">
{% include "js/webhook.js" %}
{% include "js/multipart_form_data.js" %}
{% include "js/rfc822_date.js" %}
var feedbackEl;
var formEl;
var payloadEl;
var fromEl;
var toEl;
var ccEl;
var subjectEl;
var bodyEl;
var contentLengthEl;
//var contentTypeEl;
var sendInboundMailWebhook = function() {
if (!feedbackEl) {
feedbackEl = document.getElementById('feedback');
formEl = document.getElementById('inboundmail-form');
fromEl = document.getElementById('from');
toEl = document.getElementById('to');
ccEl = document.getElementById('cc');
subjectEl = document.getElementById('subject');
bodyEl = document.getElementById('body');
payloadEl = document.getElementById('payload');
contentLengthEl = document.getElementById('content-length');
}
var from = fromEl.value;
var to = toEl.value;
var cc = ccEl.value;
var subject = subjectEl.value;
var body = bodyEl.value;
if (!to || !from || !body) {
feedbackEl.className = 'ae-errorbox';
feedbackEl.innerHTML = 'From, To and Message body are required.';
return;
}
feedbackEl.className = 'ae-message';
feedbackEl.innerHTML = 'Sending mail message...';
var mpfd = new MultipartFormData();
mpfd.addHeader('MIME-Version', '1.0');
mpfd.addHeader('Date', RFC822Date.format(new Date()));
mpfd.addHeader('From', from);
mpfd.addHeader('To', to);
if (cc) {
mpfd.addHeader('Cc', cc);
}
mpfd.addHeader('Subject', subject);
mpfd.addHeader('Content-Type', 'multipart/alternative; ' +
'boundary=' + mpfd.boundary);
mpfd.addPart(null, body, 'text/plain; charset=UTF-8');
mpfd.addPart(null, body, 'text/html; charset=UTF-8');
payloadEl.value = mpfd.toString();
contentLengthEl = payloadEl.value.length;
formEl.action = '/_ah/mail/' + escape(to);
(new Webhook('inboundmail-form')).run(handleInboundMailResult);
// Prevents actual form posts.
return false;
};
var handleInboundMailResult = function(hook, req, error) {
if (error != null || req == null || req.status != 200) {
feedbackEl.className = 'ae-errorbox';
feedbackEl.innerHTML = 'Message send failure<br>' +
req.responseText;
} else {
var timestamp;
var dateString = new Date().toString();
var match = dateString.match(/(\d\d:\d\d:\d\d).+\((.+)\)/);
if (!match || !match[0] || !match[2]) {
timestamp = dateString;
} else {
timestamp = match[1] + ' ' + match[2];
}
feedbackEl.className = 'ae-message';
feedbackEl.innerHTML = 'Message has been sent at ' + timestamp;
}
};
</script>
{% endblock %}
{% block body %}
<div id="inboundmail">
<h3>Email</h3>
{% if inboundmail_configured %}{% else %}
<div class="ae-errorbox">
Inbound mail is not yet configured properly in your app.yaml in the services section.
</div>
{% endif %}
<div id="feedback"></div>
<form id="inboundmail-form"
action="/_ah/mail/" method="post"
onsubmit="sendInboundMailWebhook(); return false">
<input type="hidden" name="payload" id="payload">
<input type="hidden" id="content-type" name="header:Content-Type" value="message/rfc822">
<input type="hidden" id="content-length" name="header:Content-Length">
<div class="fieldset">
<label for="from">From:</label>
<input type="text" id="from" name="from" size="40">
</div>
<div class="fieldset">
<label for="to">To:</label>
<input type="text" id="to" name="to" size="40">
</div>
<div class="fieldset">
<label for="cc">Cc:</label>
<input type="text" id="cc" name="cc" size="40">
</div>
<div class="fieldset">
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject" size="40">
</div>
<div id="body-c" class="fieldset">
<label for="body">Message body (plain text):</label>
<textarea id="body" name="body" rows="10" cols="50"></textarea>
</div>
<div id="inboundmail-submit">
<input type="submit" value="Send Email">
</div>
</form>
</div>
{% endblock %}
{% block final %}
{% endblock %}
|