-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
146 lines (134 loc) · 4.42 KB
/
app.js
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
var express = require('express');
var fs = require('fs');
//var mongoose = require('mongoose');
//var Schema = mongoose.Schema,
//ObjectId = Schema.ObjectId;
//var email = require('mailer');
var smtpc = require('smtpc'),mail;
//var email = require('emailjs');
//var mail = require('module/calendar.js').Email;
var app = module.exports = express.createServer();
app.configure(function(){
app.set('views',__dirname + '/views');
app.set('view engine','jade');
app.register('.html',require('jade'));
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use('/public',express.static(__dirname + '/public'));
//app.use(express.router);
});
app.set('view options',{layout:false});
app.get('/mail',function(req,res){
res.render('mail');
});
app.get('/',function(req,res){
res.render('index');
});
app.post('/send',function(req,res){
var message = "";
message += "BEGIN:VCALENDAR\n";
message += "METHOD:REQUEST\n";
message += "PRODID:Microsoft Exchange Server 2010\n";
message += "VERSION:2.0\n";
message += "BEGIN:VTIMEZONE\n";
message += "TZID:China Standard Time\n";
message += "BEGIN:STANDARD\n";
message += "DTSTART:16010101T000000\n";
message += "TZOFFSETFROM:+0800\n";
message += "TZOFFSETTO:+0800\n";
message += "END:STANDARD\n";
message += "BEGIN:DAYLIGHT\n";
message += "DTSTART:16010101T000000\n";
message += "TZOFFSETFROM:+0800\n";
message += "TZOFFSETTO:+0800\n";
message += "END:DAYLIGHT\n";
message += "END:VTIMEZONE\n";
message += "BEGIN:VEVENT\n";
message += "ORGANIZER:MAILTO: [email protected]\n";
message += "DTStart:" + Date.parse(2011,12,20,14,30,00) + "\n";
message += "DTEnd:" + Date.parse(2011,12,20,16,30,00) + "\n";
message += "Location;ENCODING=QUOTED-PRINTABLE: My home\n";
message += "UID:"+Date.parse(2011,12,20,14,30,00)+Date.parse(2011,12,20,16,30,00) + "\n";
message += "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=淘宝-UED-前端业务支撑-交易&新业务:MAILTO:[email protected]\n";
message += "ATTACH:CID:[email protected]\n";
message += "CLASS:PUBLIC\n";
message += "PRIORITY:5\n";
message += "DTSTAMP:20111126T152649Z\n";
message += "TRANSP:OPAQUE\n";
message += "STATUS:CONFIRMED\n";
message += "SEQUENCE:0\n";
message += "X-MICROSOFT-CDO-APPT-SEQUENCE:0\n";
message += "X-MICROSOFT-CDO-OWNERAPPTID:1205516251\n";
message += "X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE\n";
message += "X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\n";
message += "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE\n";
message += "X-MICROSOFT-CDO-IMPORTANCE:1\n";
message += "X-MICROSOFT-CDO-INSTTYPE:0\n";
message += "X-MICROSOFT-DISALLOW-COUNTER:FALSE\n";
message += "SUMMARY:Appointment Reminder\n";
message += "DESCRIPTION:Test message\n";
message += "PRIORITY:5\n";
message += "END:VEVENT\n";
message += "END:VCALENDAR\n";
fs.writeFile('files/calendar.ics',message,encoding='utf-8',function(err){
if(err) throw err;
console.log('It\'s saved!');
});
mail = smtpc.sendmail({
'host' : 'smtp.gmail.com',
'auth' : ['xj032085','59685713868260'],
'from' : '[email protected]',
'to' : '[email protected]',
'content' : {
'from' : 'xujie',
'to' : 'test',
'subject' : 'hello',
'content-type' : 'multipart/alternative',
'content' : [{
'content-type' : 'text/plain',
'content' : 'Hello world!'
},{
'content-type' : 'text/calendar',
'content' : message
}]
},
"success" : function () {
console.log("sent!");
process.exit(0);
},
"failure" : function (err) {
if (err.code) {
console.log("Error(%s): %s", err.email, err.message);
return;
}
console.log("Error(%d): %s", err.code, err.message);
process.exit(1);
}
});
/*
var headers = {
text:"i hope this works",
from:"qiyou<[email protected]>",
to:"haha<[email protected]>",
//to:"haha<[email protected]>",
subject:"testing emailjs"
};
var data = email.calender.create(headers);
fs.writeFile('files/calendar.ics',message,encoding='utf-8',function(err){
if(err) throw err;
console.log('It\'s saved!');
});
//data.attach_alternative("<html>i <i>hope</i> this works!</html>");
data.attach_alternative(message);
//data.attach("files/calendar.ics","text/calendar","calendar.ics");
data.attach("files/calendar.ics","application/ics","calendar.ics");
server.send(data,function(err,data){console.log(err || data);});
*/
res.redirect('/');
});
try{
app.listen(3005);
console.log('blog start!');
}catch(e){
console.log('Error: ' + e.message);
}