forked from Paul-Riggott/PS-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BridgeMail.jsx
172 lines (165 loc) · 6.76 KB
/
BridgeMail.jsx
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#target bridge
if( BridgeTalk.appName == "bridge" ) {
bridgeMail = new MenuElement("command", "Mail Selected Items", "at the end of Thumbnail");
}
bridgeMail.onSelect = function () {
mainBridgeMail();
}
function mainBridgeMail(){
AB= new File("~/AdressBook.txt");
if(!AB.exists) updateAddessBook();
var items = app.document.selections;
var dlg =
"dialog{text:'Script Interface',bounds:[100,100,760,530],"+
"panel0:Panel{bounds:[10,10,650,420] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:false},"+
"mes:StaticText{bounds:[10,120,190,140] , text:'Message Header' ,properties:{scrolling:undefined,multiline:undefined}},"+
"messHeader:EditText{bounds:[230,120,620,140] , text:'As requested..' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"mess:StaticText{bounds:[10,170,250,190] , text:'Message - For a new line use Ctrl\/J' ,properties:{scrolling:undefined,multiline:undefined}},"+
"address:Button{bounds:[255,170,390,190] , text:'Update AddressBook' },"+
"attachments:StaticText{bounds:[410,170,600,195] , text:'Attachments' ,properties:{scrolling:undefined,multiline:undefined}},"+
"messageText:EditText{bounds:[10,200,620,370] , text:'' ,properties:{multiline:true,noecho:false,readonly:false}},"+
"mail:StaticText{bounds:[10,80,111,100] , text:'Mail To:' ,properties:{scrolling:undefined,multiline:undefined}},"+
"mailTo:EditText{bounds:[230,80,620,100] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"addBook:StaticText{bounds:[10,50,100,70] , text:'Address Book:' ,properties:{scrolling:undefined,multiline:undefined}},"+
"adBook:DropDownList{bounds:[230,50,620,70]},"+
"edit:Button{bounds:[101,50,228,70] , text:'Edit Adresss Book' },"+
"button0:Button{bounds:[10,380,290,401] , text:'Send Mail' },"+
"button1:Button{bounds:[330,380,610,401] , text:'Cancel' },"+
"title:StaticText{bounds:[250,10,580,40] , text:'BridgeMail' ,properties:{scrolling:undefined,multiline:undefined}}}};";
var win = new Window(dlg,"BridgeMail");
if(app.version.substr(0,app.version.indexOf('.'))>1){
win.panel0.title.graphics.font = ScriptUI.newFont("Times","BOLDITALIC",26);
win.panel0.attachments.graphics.font = ScriptUI.newFont("Times","BOLD",14);
g = win.graphics;
b=win.panel0.title.graphics;
a=win.panel0.attachments.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
var myPen =b.newPen (g.PenType.SOLID_COLOR, [0.00, 0.00, 0.99, 1],lineWidth=1);
var myPen2 =b.newPen (g.PenType.SOLID_COLOR, [0.99, 0.00, 0.00, 1],lineWidth=1);
var myPen3 =b.newPen (g.PenType.SOLID_COLOR, [0.00, 0.00, 0.00, 1],lineWidth=1);
g.foregroundColor = myPen;
b.foregroundColor = myPen2;
a.foregroundColor = myPen3;
}
var addressBookArray = new Array();
AB.open("r");
while(!AB.eof){
var mailAD = AB.readln();
if (mailAD.length >3) addressBookArray.push(mailAD);
}
AB.close();
addressBookArray = addressBookArray.sort();
for (i in addressBookArray) {
win.panel0.adBook.add('item',addressBookArray[i]);
}
win.panel0.adBook.selection=0;
win.panel0.mailTo.text = addressBookArray[0];
win.panel0.adBook.onChange = function(){
win.panel0.mailTo.text = this.selection.text;
}
win.panel0.attachments.text = items.length + " attachment(s) will be sent.";
win.panel0.edit.onClick = function() {
AB.execute();
}
win.panel0.address.onClick=function(){
updateAddessBook();
AB.open("r");
while(!AB.eof){
var mailAD = AB.readln();
if (mailAD.length >3) addressBookArray.push(mailAD);
}
AB.close();
win.panel0.adBook.removeAll();
addressBookArray = addressBookArray.sort();
for (i in addressBookArray) {
win.panel0.adBook.add('item',addressBookArray[i]);
}
win.panel0.adBook.selection=0;
win.panel0.mailTo.text = addressBookArray[0];
}
win.panel0.button0.onClick = function() {
var mess = validate();
if(mess != true){
alert(mess);
}else{
this.parent.parent.close(1);
}
}
win.center();
var done = false;
while (!done) {
var x = win.show();
if (x == 0 || x == 2) {
win.canceled = true;
done = true;
} else if (x == 1) {
done = true;
processMail();
}
}
function validate(){
if(win.panel0.mailTo.text == '') return "No Email Address entered";
if(win.panel0.messageText.text == '') return "No message entered";
return true;
}
function processMail(){
var BM = new File("~/BridgeSendMail.vbs");
if(BM.exists) BM.remove();
BM.open("e");
BM.writeln("Dim ToAddress");
BM.writeln("Dim MessageSubject");
BM.writeln("Dim MessageBody");
BM.writeln("Dim myAttachments");
BM.writeln("Dim ol, ns, newMail");
BM.writeln("ToAddress = \"" + win.panel0.mailTo.text +"\"");
BM.writeln("MessageSubject = \""+ win.panel0.messHeader.text + "\"");
var bulkText = win.panel0.messageText.text;
bulkText = bulkText.replace(/\n/g, "\" & vbCrLf & \"");
BM.writeln("MessageBody = \"" + bulkText + "\"");
BM.writeln("Set ol = WScript.CreateObject(\"Outlook.Application\")");
BM.writeln("Set ns = ol.getNamespace(\"MAPI\")");
BM.writeln("ns.logon \"\",\"\",true,false");
BM.writeln("Set newMail = ol.CreateItem(olMailItem)");
BM.writeln("newMail.Subject = MessageSubject");
BM.writeln("newMail.Body = MessageBody & vbCrLf");
for(a=0;a<items.length;a++){
BM.writeln("newMail.Attachments.Add \"" + items[a].path + "\"");
}
BM.writeln("Set myRecipient = ns.CreateRecipient(ToAddress)");
BM.writeln("myRecipient.Resolve");
BM.writeln("If Not myRecipient.Resolved Then");
BM.writeln("MsgBox \"unknown recipient\"");
BM.writeln("Else");
BM.writeln("newMail.Recipients.Add(myRecipient)");
BM.writeln("newMail.Send");
BM.writeln("End If");
BM.writeln("Set ol = Nothing");
BM.writeln(" ");
BM.close();
BM.execute();
}
function updateAddessBook(){
var UAB = new File("~/updateAddressBook.vbs");
UAB.open('w');
UAB.writeln('On Error Resume Next');
UAB.writeln('Set wshShell = WScript.CreateObject("WScript.Shell")');
UAB.writeln('Set wshSysEnv = wshShell.Environment("PROCESS")');
UAB.writeln('sMyFile = "c:" & wshSysEnv("HOMEPATH") & "\\AdressBook.txt"');
UAB.writeln('Dim objFileSystem, objOutputFile');
UAB.writeln('Dim strOutputFile');
UAB.writeln('Set objFileSystem = CreateObject("Scripting.fileSystemObject")');
UAB.writeln('Set objOutputFile = objFileSystem.CreateTextFile(sMyFile, TRUE)');
UAB.writeln('Const olFolderContacts = 10 ');
UAB.writeln('Set objOutlook = CreateObject("Outlook.Application") ');
UAB.writeln('Set objNamespace = objOutlook.GetNamespace("MAPI") ');
UAB.writeln('Set colContacts = objNamespace.GetDefaultFolder(olFolderContacts).Items ');
UAB.writeln('For Each objContact In colContacts ');
UAB.writeln('objOutputFile.WriteLine( objContact.Email1Address )');
UAB.writeln('Next ');
UAB.close();
UAB.execute();
$.sleep(500);
//UAB.remove();
}
}//end main