/** Wrapper Class of MCF_EMAIL; **/ /** Just Import the class, then Call Sendmail(), SetAttachment , Compose & Send **/ /** import DBT_PCLOG:*; Local DBT_PCLOG:Sendmail &oEmail = create DBT_PCLOG:Sendmail("oraclepeople..t@dbtutor.com", "nayan...@gmail.com,nay...@yahoo.com", "nan..@gmail.com,mai..@dbtutor.com", "", "oraclepeopl..@dbtutor.com"); &oEmail.SetAttachment("D:\ChatExtension.pdf", "ChatExtension.pdf"); &oEmail.Compose("Hello World - " | %DbName, "body content" | %DbName); &oEmail.Send(); MessageBox(0, "", 0, 0, "" | &oEmail.EmailResult); MessageBox(0, "", 0, 0, "" | &oEmail.EmailResultText); **/ /** Written 21-Oct-2014 **/ /** Ver - 1 **/ import PT_MCF_MAIL:*; class Sendmail method Sendmail(&sFrom As string, &sTo As string, &sCC As string, &sBCC As string, &sReplyTo As string); method SetAttachment(&sFileAttachPath As string, &sFileAttachName As string); method Compose(&EmailSubjectLine As string, &EmailBodyLine As string); method Send(); /* Email Addresses Settings */ property string EmailFrom; property string EmailTo; property string EmailCC; property string EmailBCC; property string EmailReplyTo; /* Email message properties */ property string EmailSubject; property string EmailText; /* Email Set Attachment File */ property string FileAttachment; property string AttachFile; property string AttachFileTitle; /* Send Email Delivery result */ property number EmailResult; property string EmailResultText; private Constant &HTML_CONTENT_TYPE = "text/html"; Constant &HTML_CHARSET = "UTF-8"; method GetResultText(&nResultCd As number) Returns string; instance PT_MCF_MAIL:MCFOutboundEmail &oEmail; instance PT_MCF_MAIL:MCFBodyPart &oHtml; instance PT_MCF_MAIL:MCFMultipart &OMp; instance PT_MCF_MAIL:MCFBodyPart &oAttach; end-class; /** Sendmail works as contructor **/ method Sendmail /+ &sFrom as String, +/ /+ &sTo as String, +/ /+ &sCC as String, +/ /+ &sBCC as String, +/ /+ &sReplyTo as String +/ /** Create MCFOutboundEmail class object **/ &oEmail = create PT_MCF_MAIL:MCFOutboundEmail(); /** Create MCFBodyPart class object **/ &oHtml = create PT_MCF_MAIL:MCFBodyPart(); /** Create MCFMultiPart class object **/ &OMp = create PT_MCF_MAIL:MCFMultipart(); /** Crete MCFBodyPart class object **/ &oAttach = create PT_MCF_MAIL:MCFBodyPart(); &EmailFrom = LTrim(RTrim(&sFrom, " "), " "); &EmailTo = LTrim(RTrim(&sTo, " "), " "); &EmailCC = LTrim(RTrim(&sCC, " "), " "); &EmailBCC = LTrim(RTrim(&sBCC, " "), " "); &EmailReplyTo = LTrim(RTrim(&sReplyTo, " "), " "); &oEmail.Importance = "high"; /* Importance High */ &oEmail.Priority = 1; /* Priority High */ If %This.EmailFrom <> "" Then &oEmail.From = %This.EmailFrom; Else &oEmail.From = "oraclepeoplesoft@dbtutor.com"; End-If; &oEmail.Recipients = %This.EmailTo; If %This.EmailCC <> "" Then &oEmail.CC = %This.EmailCC; End-If; If %This.EmailBCC <> "" Then &oEmail.BCC = %This.EmailBCC; End-If; If %This.EmailReplyTo <> "" Then &oEmail.ReplyTo = %This.EmailReplyTo; End-If; end-method; /** Set Attachment Content **/ /** Please Note - By default File Path Settings is %FilePath_Absolute **/ method SetAttachment /+ &sFileAttachPath as String, +/ /+ &sFileAttachName as String +/ /* Do Some Validations */ &AttachFile = LTrim(RTrim(&sFileAttachPath, " "), " "); &AttachFileTitle = LTrim(RTrim(&sFileAttachName, " "), " "); If %This.AttachFile <> "" And %This.AttachFileTitle <> "" Then &oAttach.SetAttachmentContent(&sFileAttachPath, %FilePath_Absolute, &sFileAttachName, &sFileAttachName, "", ""); &oAttach.Disposition = "Attachment"; /** Set Content Disposition As Attachment **/ &OMp.AddBodyPart(&oAttach); End-If; end-method; /** Compse Email with Subject & Body **/ method Compose /+ &EmailSubjectLine as String, +/ /+ &EmailBodyLine as String +/ &oHtml.AddHeader("Content-Type", &HTML_CONTENT_TYPE); &oHtml.ContentType = &HTML_CONTENT_TYPE; &oHtml.Charset = &HTML_CHARSET; %This.EmailSubject = &EmailSubjectLine; &oEmail.Subject = %This.EmailSubject; %This.EmailText = &EmailBodyLine; &oHtml.Text = %This.EmailText; /** Set the SubType property **/ &OMp.SubType = "alternative; differences=Content-type"; /* Add the body parts created earlier to the multi part object */ &OMp.AddBodyPart(&oHtml); /* Set the multi part object to the Outbound email object */ &oEmail.MultiPart = &OMp; end-method; /** Send Email,it will return Result Code & Result Text **/ method Send %This.EmailResult = &oEmail.Send(); %This.EmailResultText = %This.GetResultText(%This.EmailResult); end-method; /** Private Methods, Used for Email Delivery Status Message **/ method GetResultText /+ &nResultCd as Number +/ /+ Returns String +/ Evaluate &nResultCd When = %ObEmail_Delivered REM Return 1; Return "Email was delivered Successfully"; Break; When = %ObEmail_NotDelivered REM Return 2; Return "Email delivery not attempted"; Break; When = %ObEmail_PartiallyDelivered REM Return 3; Return "Email has only been partially delivered. Only some of the addresses in the list of addresses were delivered to"; Break; When = %ObEmail_FailedBeforeSending REM Return 0; Return "Failed before sending, not delivered"; Break; When = %ObEmail_SentButResultUnknown REM -1; Return "Email was Sent but delivery status is unknown"; Break; When-Other Return "Unknown result, most likely not delivered. Please Contact your system administrator"; Break; End-Evaluate; end-method;