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