forked from bruce-armstrong/pbnismtp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pbnismtp.cpp
903 lines (812 loc) · 23 KB
/
pbnismtp.cpp
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
#include "CSMTPConnection\stdafx.h"
#include <pbext.h>
#include "pbnismtp.h"
#include "CSMTPConnection\PJNSMTP.h"
#include <tchar.h>
BOOL APIENTRY DllMain(
HANDLE hModule,
DWORD reasonForCall,
LPVOID lpReserved
)
{
switch( reasonForCall )
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
PBXEXPORT LPCTSTR PBXCALL PBX_GetDescription()
{
static const TCHAR desc[] =
{
_T ( "class n_cpp_smtp from nonvisualobject\n" )
_T ( "function int Send ( )\n" )
_T ( "subroutine SetMessage ( string pbmessage )\n" )
_T ( "subroutine SetMessage ( string pbmessage, boolean pbHTML )\n" )
_T ( "subroutine SetRecipientEmail ( string pbrecipientemail )\n" )
_T ( "subroutine SetCCRecipientEmail ( string pbCCrecipientemail )\n" )
_T ( "subroutine SetBCCRecipientEmail ( string pbBCCrecipientemail )\n" )
_T ( "subroutine SetReplyToEmail ( string pbreplytoemail )\n" )
_T ( "subroutine SetSenderEmail ( string pbsenderemail )\n" )
_T ( "subroutine SetSMTPServer ( string pbsmtpserver )\n" )
_T ( "subroutine SetSubject ( string pbsubject )\n" )
_T ( "subroutine SetAttachment ( string pbattachment )\n" )
_T ( "subroutine SetErrorMessagesOn ( )\n" )
_T ( "subroutine SetErrorMessagesOff ( )\n" )
_T ( "subroutine SetCharSet ( string pbcharset )\n" )
_T ( "subroutine SetUsernamePassword ( string pbusername, string pbpassword )\n" )
_T ( "subroutine SetPort ( integer port )\n" )
_T ( "subroutine SetAuthMethod ( integer authmethod )\n" )
_T ( "subroutine SetConnectionType ( integer connecttype )\n" )
_T ( "function string GetLastErrorMessage ( )\n")
_T ( "subroutine SetPriority ( integer pbpriority )\n" )
_T ( "subroutine SetReadReceiptRequested ( boolean pbboolean )\n" )
_T ( "subroutine SetOriginatorDeliveryReportRequested ( boolean pbboolean )\n" )
_T ( "subroutine SetMessage ( string pbplainmessage, string pbhtmlmessage )\n")
_T ( "subroutine SetAttachment ( string pbattachment, string pbcontentid, string pbcontenttype )\n")
_T ( "subroutine SetAttachmentBase64 ( string pbattachment, string pbfilename, string pbcontentid, string pbcontenttype )\n")
_T ( "subroutine SetMailerName ( string pbname )\n")
_T ( "subroutine SetPriorityNone ( )\n")
_T ( "subroutine SetPriorityLow ( )\n")
_T ( "subroutine SetPriorityNormal ( )\n")
_T ( "subroutine SetPriorityHigh ( )\n")
_T ( "subroutine SetHeader ( string pbheadername, string pbheadervalue )\n")
_T ( "end class\n" )
};
return (LPCTSTR)desc ;
}
PBXEXPORT PBXRESULT PBXCALL PBX_CreateNonVisualObject(
IPB_Session* pbsession,
pbobject pbobj,
LPCTSTR className,
IPBX_NonVisualObject **obj
)
{
LPCTSTR myclassname = _T ( "n_cpp_smtp" ) ;
if ( _tcscmp( className, myclassname ) == 0 )
{
*obj = new CSMTP() ;
return PBX_OK ;
} ;
*obj = NULL ;
return PBX_E_NO_SUCH_CLASS ;
}
enum MethodIDs
{
SEND = 0,
SETMESSAGE = 1,
SETMESSAGEHTML = 2,
SETRECIPIENTEMAIL = 3,
SETCCRECIPIENTEMAIL = 4,
SETBCCRECIPIENTEMAIL = 5,
SETREPLYTOEMAIL = 6,
SETSENDEREMAIL = 7,
SETSMTPSERVER = 8,
SETSUBJECT = 9,
SETATTACHMENT = 10,
SETERRORMESSAGESON = 11,
SETERRORMESSAGESOFF = 12,
SETMSGCHARSET = 13,
SETUSERNAMEPASSWORD = 14,
SETPORT = 15,
SETAUTHMETHOD = 16,
SETCONNECTIONTYPE = 17,
GETLASTERRORMESSAGE = 18,
SETPRIORITY = 19,
SETREADRECEIPTREQUEST = 20,
SETORIGINATORDELIVERYREPORTREQUESTED = 21,
SETMESSAGEPLAINHTML = 22,
SETATTACHEMENTEXTRA = 23,
SETATTACHMENTBASE64 = 24,
SETMAILERNAME = 25,
SETPRIORITYNONE = 26,
SETPRIORITYLOW = 27,
SETPRIORITYNORMAL = 28,
SETPRIORITYHIGH = 29,
SETHEADER = 30,
ENTRY_COUNT
};
DWORD CSMTP::m_dwRefCount = 0;
CSMTP::CSMTP()
{
WSADATA wd;
if( ++m_dwRefCount == 1 )
{
::WSAStartup( 0x0101, &wd );
}
MessageArg = NULL ;
SenderEmailArg = NULL ;
RecipientEmailArg = NULL ;
CCRecipientEmailArg = NULL ;
BCCRecipientEmailArg = NULL ;
ReplyToEmailArg = NULL;
SMTPServerArg = NULL ;
SubjectArg = NULL ;
AttachmentArg = NULL ;
CharSetArg = NULL ;
UsernameArg = NULL ;
PasswordArg = NULL ;
PriorityArg = NULL ;
ReadReceiptArg = NULL ;
DeliverReportArg = NULL ;
HeaderArg = NULL ;
Message = NULL;
HTMLMessage = NULL;
SenderEmail = NULL;
RecipientEmail = NULL;
CCRecipientEmail = NULL;
BCCRecipientEmail = NULL;
ReplyToEmail = NULL;
SMTPServer = NULL;
Subject = NULL;
Attachment = NULL;
Username = NULL ;
Password = NULL ;
HeaderName = NULL;
HeaderValue = NULL;
CharSet = _T("iso-8859-1");
ErrorMessageBoxesOn = FALSE; /* initialize to off */
HTMLBody = FALSE ;
PLAINHTMLBody = FALSE;
Port = 25 ;
AuthMethod = 5 ; /* Default to Auto Detect */
ConnectType = 0 ; /* Default to Plain Text */
MailerName = _T("PBNISMTP 3.2");
}
CSMTP::~CSMTP(void)
{
if( --m_dwRefCount == 0 )
{
::WSACleanup();
}
}
int CSMTP::Send()
{
TCHAR title[] = _T("Debug");
CPJNSMTPConnection connection;
CPJNSMTPMessage msg;
BOOLEAN CloseGracefully = TRUE;
INT ReturnCode = UNDEFINEDERR;
// Validate the passed in values first
if (SenderEmail == NULL)
{
return INVALIDSENDEREMAIL;
}
if (RecipientEmail == NULL && CCRecipientEmail == NULL && BCCRecipientEmail == NULL)
{
return INVALIDRECIPIENTEMAIL;
}
if (SMTPServer == NULL)
{
return INVALIDSMTPSERVER;
}
if (Subject == NULL)
{
Subject = _T("");
}
if (Message == NULL)
{
Message = _T("");
}
try
{
// Set the Return Code if Exception is raised for the following calls
ReturnCode = INVALIDRECIPIENTEMAIL;
// Set the Charset
msg.SetCharset ( CharSet ) ;
// Set the Sender
msg.m_From = CPJNSMTPAddress(SenderEmail);
// Set the Recipient
msg.ParseMultipleRecipients ( RecipientEmail, msg.m_To ) ;
// Set the CC
if ( CCRecipientEmail != NULL )
{
msg.ParseMultipleRecipients ( CCRecipientEmail, msg.m_CC ) ;
}
// Set the BCC
if ( BCCRecipientEmail != NULL )
{
msg.ParseMultipleRecipients ( BCCRecipientEmail, msg.m_BCC ) ;
}
// Set the Reply To
if ( ReplyToEmail != NULL )
{
msg.ParseMultipleRecipients( ReplyToEmail, msg.m_ReplyTo );
}
// Set the Return Code if Exception is raised for the following calls
ReturnCode = MESSAGEBODYERROR;
// Set the subject and message
msg.m_sSubject = (CString)Subject ;
msg.m_sXMailer = MailerName;
// Set Read Receipt header
if ( READRECEIPT == TRUE )
{
#ifdef _DEBUG
MessageBox(NULL, _T("Set Disposition-Notification-To Header"), title, MB_ICONEXCLAMATION | MB_OK);
#endif
CString dString;
dString.Format(_T("Disposition-Notification-To: %s"), SenderEmail);
msg.m_CustomHeaders.push_back((CPJNSMTPString)dString);
}
// Set Delivery report header
if ( DELIVERYREPORT == TRUE )
{
#ifdef _DEBUG
MessageBox(NULL, _T("Set Delivery Report Header"), title, MB_ICONEXCLAMATION | MB_OK);
#endif
msg.m_DSNReturnType = CPJNSMTPMessage::FullEmail;
msg.m_dwDSN = CPJNSMTPMessage::DSN_NOT_SPECIFIED;
msg.m_dwDSN |= CPJNSMTPMessage::DSN_SUCCESS;
#ifdef CPJNSMTP_MFC_EXTENSIONS
msg.m_MessageDispositionEmailAddresses.Add(SenderEmail);
#else
msg.m_MessageDispositionEmailAddresses.push_back(CPJNSMTPString(SenderEmail));
#endif
}
// Set Priority Header
if (PRIORITY != NULL)
{
#ifdef _DEBUG
MessageBox(NULL, _T("Set Priority Header"), title, MB_ICONEXCLAMATION | MB_OK);
#endif
msg.m_Priority = msg.NoPriority;
if (PRIORITY == 3)
{
msg.m_Priority = msg.HighPriority;
}
else if (PRIORITY == 2)
{
msg.m_Priority = msg.NormalPriority;
}
else if (PRIORITY == 1)
{
msg.m_Priority = msg.LowPriority;
}
}
if ( HTMLBody == TRUE )
{
// Only HTML Message
msg.SetMime(TRUE) ;
msg.AddHTMLBody(Message);
}
else if (PLAINHTMLBody == TRUE)
{
// multipart plain/html message
CPJNSMTPBodyPart RootPart;
CPJNSMTPBodyPart MessagePart;
CPJNSMTPBodyPart TextPart;
CPJNSMTPBodyPart HTMLPart;
RootPart = msg.m_RootPart;
msg.SetMime(TRUE);
MessagePart.SetCharset(RootPart.GetCharset().c_str());
MessagePart.SetText(_T(""));
MessagePart.SetContentType(_T("multipart/alternative"));
TextPart.SetCharset(RootPart.GetCharset().c_str());
TextPart.SetText(Message);
TextPart.SetContentType(_T("text/plain"));
MessagePart.AddChildBodyPart(TextPart);
HTMLPart.SetCharset(RootPart.GetCharset().c_str());
HTMLPart.SetText(HTMLMessage);
HTMLPart.SetContentType(_T("text/html"));
MessagePart.AddChildBodyPart(HTMLPart);
msg.AddBodyPart(MessagePart);
}
else
{
// Only PlainText Message
msg.AddTextBody (Message) ;
}
// Add any attachment
if ( Attachment != NULL )
{
msg.AddMultipleAttachments(Attachment);
}
// Set any attachement in array
for (std::vector<AttachmentFile*>::size_type i = 0; i < m_AttachmentFile.size(); i++)
{
CPJNSMTPBodyPart BodyPart;
BodyPart.SetFilename(m_AttachmentFile[i].Filename);
BodyPart.SetContentID(m_AttachmentFile[i].ContentID);
BodyPart.SetContentType(m_AttachmentFile[i].ContentType);
msg.AddBodyPart(BodyPart);
}
// Set Embedded Attachements
for (std::vector<AttachmentBase64*>::size_type i = 0; i < m_AttachmentBase64.size(); i++)
{
CPJNSMTPBodyPart imageBodyPart;
imageBodyPart.SetRawBody(m_AttachmentBase64[i].Base64);
imageBodyPart.SetAttachment(TRUE);
imageBodyPart.SetContentID(m_AttachmentBase64[i].ContentID);
imageBodyPart.SetContentType(m_AttachmentBase64[i].ContentType);
imageBodyPart.SetTitle(m_AttachmentBase64[i].FileName);
msg.AddBodyPart(imageBodyPart);
}
// Set Headers
for (std::vector<CustomHeader*>::size_type i = 0; i < m_CustomHeaders.size(); i++)
{
CString dString;
dString.Format(_T("%s: %s"), m_CustomHeaders[i].Name, m_CustomHeaders[i].Value);
msg.m_CustomHeaders.push_back((CPJNSMTPString)dString);
}
// Set the Return Code if Exception is raised for the following calls
ReturnCode = SMTPCONNECTFAILED;
// Connect to SMTP server
#ifdef _DEBUG
MessageBox(NULL, _T("Connecting to SMTP Server"), title, MB_ICONEXCLAMATION | MB_OK);
#endif
connection.Connect(SMTPServer, CPJNSMTPConnection::AuthenticationMethod(AuthMethod), Username, Password, Port, CPJNSMTPConnection::ConnectionType(ConnectType));
// Set the Return Code if Exception is raised for the following calls
ReturnCode = MESSAGESENDERROR;
// Now send the message
#ifdef _DEBUG
MessageBox(NULL, _T("Sending Message"), title, MB_ICONEXCLAMATION | MB_OK);
#endif
connection.SendMessage ( msg ) ;
// Everything was Successful!
ReturnCode = SUCCESSFUL;
}
#ifdef CPJNSMTP_MFC_EXTENSIONS
catch (CPJNSMTPException* pEx)
{
CloseGracefully = FALSE;
LastErrorMsg = pEx->m_sLastResponse;
if (LastErrorMsg == "")
{
LastErrorMsg = (CString) pEx->GetErrorMessage().operator LPCTSTR();
}
if (ErrorMessageBoxesOn == TRUE)
{
//Display the error
CString sMsg;
sMsg.Format(_T("Could not send message: Error:%08X\nDescription:%s"), pEx->m_hr, LastErrorMsg);
MessageBox(NULL, sMsg, title, MB_ICONEXCLAMATION | MB_OK);
}
pEx->Delete();
}
#else
catch (CPJNSMTPException& e)
{
CloseGracefully = FALSE;
LastErrorMsg = e.m_sLastResponse.c_str();
if (LastErrorMsg == "")
{
TCHAR szError[4096];
szError[0] = _T('\0');
e.GetErrorMessage(szError, _countof(szError));
LastErrorMsg = (CString) szError;
}
// when SMTP server doesn't support DSN you will get an empty error, give enduser a beter error message.
if (e.m_hr == 0x80040227 && DELIVERYREPORT == TRUE)
{
CString sMsg;
sMsg.Format(_T("SMTP Server doesn't support Delivery Status Notification (DSN)"));
LastErrorMsg = sMsg;
}
if (ErrorMessageBoxesOn == TRUE)
{
//Display the error
CString sMsg;
sMsg.Format(_T("Could not send message: Error:%08X\nDescription:%s"), e.m_hr, LastErrorMsg); // e.m_sLastResponse.c_str());
MessageBox(NULL, sMsg, title, MB_ICONEXCLAMATION | MB_OK);
}
}
#endif
// Disconnect from the server
try
{
if (connection.IsConnected())
connection.Disconnect(CloseGracefully);
}
#ifdef CPJNSMTP_MFC_EXTENSIONS
catch (CPJNSMTPException* pEx)
{
pEx->Delete();
}
#else
catch (CPJNSMTPException& /*e*/)
{
}
#endif
return ReturnCode ;
} ;
PBXRESULT CSMTP::Invoke(IPB_Session * session, pbobject obj, pbmethodID mid, PBCallInfo * ci)
{
Session = session ;
switch( mid )
{
case SEND:
{
int rc;
rc = Send();
ci->returnValue->SetInt((pbint)rc);
return PBX_OK;
}
case SETMESSAGE:
{
MessageArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbMessage = MessageArg->GetString() ;
Message = session->GetString(pbMessage) ;
#ifdef _DEBUG
MessageBox( NULL, Message, _T ( "Message" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETMESSAGEHTML:
{
MessageArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbMessage = MessageArg->GetString() ;
Message = session->GetString(pbMessage) ;
IPB_Value * HTMLArg = session->AcquireValue ( ci->pArgs->GetAt(1) ) ;
HTMLBody = (bool)HTMLArg->GetBool() ;
if (HTMLArg)
{
Session->ReleaseValue(HTMLArg);
}
#ifdef _DEBUG
MessageBox(NULL, Message, _T("MessageHTML"), MB_ICONEXCLAMATION | MB_OK);
#endif
return PBX_OK;
}
case SETRECIPIENTEMAIL:
{
RecipientEmailArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbRecipientEmail = RecipientEmailArg->GetString() ;
RecipientEmail = session->GetString(pbRecipientEmail) ;
#ifdef _DEBUG
MessageBox( NULL, RecipientEmail, _T ( "RecipientEmail" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETCCRECIPIENTEMAIL:
{
CCRecipientEmailArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbCCRecipientEmail = CCRecipientEmailArg->GetString() ;
CCRecipientEmail = session->GetString( pbCCRecipientEmail ) ;
#ifdef _DEBUG
MessageBox( NULL, CCRecipientEmail, _T ( "CCRecipientEmail" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETBCCRECIPIENTEMAIL:
{
BCCRecipientEmailArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbBCCRecipientEmail = BCCRecipientEmailArg->GetString() ;
BCCRecipientEmail = session->GetString( pbBCCRecipientEmail ) ;
#ifdef _DEBUG
MessageBox( NULL, BCCRecipientEmail, _T ( "BCCRecipientEmail" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETREPLYTOEMAIL:
{
ReplyToEmailArg = session->AcquireValue ( ci->pArgs->GetAt(0) );
pbstring pbReplyToEmail = ReplyToEmailArg->GetString();
ReplyToEmail = session->GetString( pbReplyToEmail );
#ifdef _DEBUG
MessageBox(NULL, ReplyToEmail, _T("ReplyToEmail"), MB_ICONEXCLAMATION | MB_OK);
#endif
return PBX_OK;
}
case SETSENDEREMAIL:
{
SenderEmailArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbSenderEmail = SenderEmailArg->GetString() ;
SenderEmail = session->GetString ( pbSenderEmail ) ;
#ifdef _DEBUG
MessageBox( NULL, SenderEmail, _T ( "SenderEmail" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETSMTPSERVER:
{
SMTPServerArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbSMTPServer = SMTPServerArg->GetString() ;
SMTPServer = session->GetString ( pbSMTPServer ) ;
#ifdef _DEBUG
MessageBox( NULL, SMTPServer, _T ( "SMTPServer" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETSUBJECT:
{
SubjectArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbSubject = SubjectArg->GetString() ;
Subject = session->GetString ( pbSubject ) ;
#ifdef _DEBUG
MessageBox( NULL, Subject, _T ( "Subject" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETATTACHMENT:
{
AttachmentArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbAttachment = AttachmentArg->GetString() ;
Attachment = session->GetString ( pbAttachment ) ;
#ifdef _DEBUG
MessageBox( NULL, Attachment, _T ( "Attachment" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETERRORMESSAGESON:
{
ErrorMessageBoxesOn = TRUE;
return PBX_OK;
}
case SETERRORMESSAGESOFF:
{
ErrorMessageBoxesOn = FALSE;
return PBX_OK;
}
case SETMSGCHARSET:
{
CharSetArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbCharSet = CharSetArg->GetString() ;
CharSet = session->GetString ( pbCharSet ) ;
#ifdef _DEBUG
MessageBox( NULL, CharSet, _T ( "CharSet" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETUSERNAMEPASSWORD:
{
UsernameArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
pbstring pbUsername = UsernameArg->GetString() ;
Username = session->GetString ( pbUsername ) ;
PasswordArg = session->AcquireValue ( ci->pArgs->GetAt(1) ) ;
pbstring pbPassword = PasswordArg->GetString() ;
Password = session->GetString ( pbPassword ) ;
#ifdef _DEBUG
MessageBox( NULL, Username, _T ( "Username" ), MB_ICONEXCLAMATION | MB_OK );
#endif
return PBX_OK;
}
case SETPORT:
{
IPB_Value * PortArg = session->AcquireValue ( ci->pArgs->GetAt(0) ) ;
Port = (int)PortArg->GetInt();
if (PortArg)
{
Session->ReleaseValue(PortArg);
}
return PBX_OK;
}
case SETAUTHMETHOD:
{
IPB_Value * AuthArg = session->AcquireValue ( ci->pArgs->GetAt(0) );
AuthMethod = (int)AuthArg->GetInt();
if (AuthArg)
{
Session->ReleaseValue( AuthArg );
}
return PBX_OK;
}
case SETCONNECTIONTYPE:
{
IPB_Value * ConnectionArg = session->AcquireValue ( ci->pArgs->GetAt(0) );
ConnectType = (int)ConnectionArg->GetInt();
if (ConnectionArg)
{
Session->ReleaseValue( ConnectionArg );
}
return PBX_OK;
}
case GETLASTERRORMESSAGE:
{
ci->returnValue->SetString(LastErrorMsg);
return PBX_OK;
}
case SETPRIORITY:
{
IPB_Value * PriorityArg = session->AcquireValue(ci->pArgs->GetAt(0));
PRIORITY = (int)PriorityArg->GetInt();
return PBX_OK;
}
case SETPRIORITYNONE:
{
PRIORITY = 0;
return PBX_OK;
}
case SETPRIORITYLOW:
{
PRIORITY = 1;
return PBX_OK;
}
case SETPRIORITYNORMAL:
{
PRIORITY = 2;
return PBX_OK;
}
case SETPRIORITYHIGH:
{
PRIORITY = 3;
return PBX_OK;
}
case SETREADRECEIPTREQUEST:
{
IPB_Value * ReadReceiptArg = session->AcquireValue(ci->pArgs->GetAt(0));
READRECEIPT = (bool)ReadReceiptArg->GetBool();
if (ReadReceiptArg)
{
Session->ReleaseValue(ReadReceiptArg);
}
return PBX_OK;
}
case SETORIGINATORDELIVERYREPORTREQUESTED:
{
IPB_Value * DeliverReportArg = session->AcquireValue(ci->pArgs->GetAt(0));
DELIVERYREPORT = (bool)DeliverReportArg->GetBool();
if (DeliverReportArg)
{
Session->ReleaseValue(DeliverReportArg);
}
return PBX_OK;
}
case SETMESSAGEPLAINHTML:
{
// Plaintext message
MessageArg = session->AcquireValue(ci->pArgs->GetAt(0));
pbstring pbMessage = MessageArg->GetString();
Message = session->GetString(pbMessage);
// HTML Mesage
MessageArg = session->AcquireValue(ci->pArgs->GetAt(1));
pbstring pbHTMLMessage = MessageArg->GetString();
HTMLMessage = session->GetString(pbHTMLMessage);
PLAINHTMLBody = TRUE;
#ifdef _DEBUG
MessageBox(NULL, Message, _T("Message"), MB_ICONEXCLAMATION | MB_OK);
MessageBox(NULL, HTMLMessage, _T("HTMLMessage"), MB_ICONEXCLAMATION | MB_OK);
#endif
return PBX_OK;
}
case SETATTACHEMENTEXTRA:
{
AttachmentArg = session->AcquireValue(ci->pArgs->GetAt(0));
pbstring pbFileName = AttachmentArg->GetString();
LPTSTR FileName = (LPTSTR)session->GetString(pbFileName);
AttachmentArg = session->AcquireValue(ci->pArgs->GetAt(1));
pbstring pbContentID = AttachmentArg->GetString();
LPTSTR ContentID = (LPTSTR)session->GetString(pbContentID);
AttachmentArg = session->AcquireValue(ci->pArgs->GetAt(2));
pbstring pbContentType = AttachmentArg->GetString();
LPTSTR ContentType = (LPTSTR)session->GetString(pbContentType);
AttachmentFile aFile;
aFile.Filename = FileName;
aFile.ContentID = ContentID;
aFile.ContentType = ContentType;
m_AttachmentFile.push_back(aFile);
return PBX_OK;
}
case SETATTACHMENTBASE64:
{
AttachmentArg = session->AcquireValue(ci->pArgs->GetAt(0));
pbstring pbBase64 = AttachmentArg->GetString();
LPCSTR Base64 = (LPCSTR)session->GetString(pbBase64);
AttachmentArg = session->AcquireValue(ci->pArgs->GetAt(1));
pbstring pbFileName = AttachmentArg->GetString();
LPTSTR FileName = (LPTSTR)session->GetString(pbFileName);
AttachmentArg = session->AcquireValue(ci->pArgs->GetAt(2));
pbstring pbContentID = AttachmentArg->GetString();
LPTSTR ContentID = (LPTSTR)session->GetString(pbContentID);
AttachmentArg = session->AcquireValue(ci->pArgs->GetAt(3));
pbstring pbContentType = AttachmentArg->GetString();
LPTSTR ContentType = (LPTSTR)session->GetString(pbContentType);
AttachmentBase64 aBase64;
aBase64.Base64 = Base64;
aBase64.FileName = FileName;
aBase64.ContentID = ContentID;
aBase64.ContentType = ContentType;
m_AttachmentBase64.push_back(aBase64);
return PBX_OK;
}
case SETMAILERNAME:
{
MailerNameArg = session->AcquireValue(ci->pArgs->GetAt(0));
pbstring pbMailerName = MailerNameArg->GetString();
MailerName = session->GetString(pbMailerName);
#ifdef _DEBUG
MessageBox(NULL, MailerName, _T("MailerName"), MB_ICONEXCLAMATION | MB_OK);
#endif
return PBX_OK;
}
case SETHEADER:
{
HeaderArg = session->AcquireValue(ci->pArgs->GetAt(0));
pbstring pbHeaderName = HeaderArg->GetString();
LPTSTR HeaderName = (LPTSTR)session->GetString(pbHeaderName);
HeaderArg = session->AcquireValue(ci->pArgs->GetAt(1));
pbstring pbHeaderValue = HeaderArg->GetString();
LPTSTR HeaderValue = (LPTSTR)session->GetString(pbHeaderValue);
CustomHeader customHeader;
customHeader.Name = HeaderName;
customHeader.Value = HeaderValue;
m_CustomHeaders.push_back(customHeader);
#ifdef _DEBUG
CString dString;
dString.Format(_T("%s: %s"), HeaderName, HeaderValue);
MessageBox(NULL, dString, _T("SetHeader"), MB_ICONEXCLAMATION | MB_OK);
delete dString;
#endif
return PBX_OK;
}
return PBX_E_INVOKE_METHOD_AMBIGUOUS;
}
}
void CSMTP::CleanUp()
{
//If any of our local IPB_Value pointers are populated
//we need to release them to avoid a memory leak
if (MessageArg)
{
Session->ReleaseValue ( MessageArg ) ;
}
if (SenderEmailArg)
{
Session->ReleaseValue ( SenderEmailArg ) ;
}
if (RecipientEmailArg)
{
Session->ReleaseValue ( RecipientEmailArg ) ;
}
if (CCRecipientEmailArg)
{
Session->ReleaseValue ( CCRecipientEmailArg ) ;
}
if (BCCRecipientEmailArg)
{
Session->ReleaseValue ( BCCRecipientEmailArg ) ;
}
if (ReplyToEmailArg)
{
Session->ReleaseValue( ReplyToEmailArg );
}
if (SMTPServerArg)
{
Session->ReleaseValue ( SMTPServerArg ) ;
}
if (SubjectArg)
{
Session->ReleaseValue ( SubjectArg ) ;
}
if (AttachmentArg)
{
Session->ReleaseValue ( AttachmentArg ) ;
}
if (CharSetArg)
{
Session->ReleaseValue ( CharSetArg ) ;
}
if (UsernameArg)
{
Session->ReleaseValue( UsernameArg );
}
if (PasswordArg)
{
Session->ReleaseValue( PasswordArg );
}
if (ReadReceiptArg)
{
Session->ReleaseValue( ReadReceiptArg );
}
if (DeliverReportArg)
{
Session->ReleaseValue( DeliverReportArg );
}
if (PriorityArg)
{
Session->ReleaseValue( PriorityArg );
}
if (HeaderArg)
{
Session->ReleaseValue(HeaderArg);
}
}
void CSMTP::Destroy()
{
//Do cleanup before exiting
CleanUp();
delete this ;
}