コード例 #1
0
    public SendEmail_Result SendEmail(string partnerUsername, string partnerPassword, string senderEmail, string receiverEmail, string subject, string message)
    {
        SendEmail_Result obj = new SendEmail_Result();
        RefRunningTBBLL runningobj = new RefRunningTBBLL();
        this.refnum = runningobj.AddRefRunningTBAndReturn();
        WSLogBLL logobj = new WSLogBLL();
        string methodName = "SendEmail";

        SendEmail sendEmailObj = new SendEmail();

        try
        {
            if (partnerUsername == "" || partnerPassword == "" || senderEmail == "" || receiverEmail == "" || subject == "" || message == "")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + senderEmail + "|" + receiverEmail + "|" + subject + "|" + message, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุข้อมูลให้ครบถ้วน";
            }
            else if (!sendEmailObj.CheckIsValidEmail(senderEmail))
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + senderEmail + "|" + receiverEmail + "|" + subject + "|" + message, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุ e-mail address ของผู้ส่งให้ถูกต้อง";
            }
            else if (!sendEmailObj.CheckIsValidEmail(receiverEmail))
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + senderEmail + "|" + receiverEmail + "|" + subject + "|" + message, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุ e-mail address ของผู้รับให้ถูกต้อง";
            }
            else
            {
                // พิสูจน์ตัวตนของพันธมิตรก่อนที่จะให้ใช้งานจริง
                NETWS_ForPartnerAuthenticationChecking.CheckPartnerAuthentication_Result pacObj = CheckPartnerAuthenticationReturnDetail(partnerUsername, partnerPassword, this.ipaddress);
                if (pacObj.Result.Trim().ToLower() == "passed")
                {
                    this.partnerName = pacObj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + senderEmail + "|" + receiverEmail + "|" + subject + "|" + message, this.refnum);

                    sendEmailObj.EmailSender = senderEmail.Trim();
                    sendEmailObj.EmailRecipient = receiverEmail.Trim();
                    sendEmailObj.EmailRecipientBCC = "";
                    sendEmailObj.Subject = subject;
                    sendEmailObj.Content = message;

                    if (sendEmailObj.Send() == true)
                    {
                        obj.Result = "completed";
                    }
                    else
                    {
                        obj.Result = "notcomplete_ไม่สามารถส่ง E-mail ให้ได้";
                    }
                }
                else
                {
                    this.partnerName = pacObj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + senderEmail + "|" + receiverEmail + "|" + subject + "|" + message, this.refnum);

                    obj.Result = pacObj.Result.Trim();
                }
            }

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result, this.refnum);

            return obj;
        }
        catch (Exception ex)
        {
            obj.Result = "notcomplete_" + ex.Message.Trim();

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result, this.refnum);

            return obj;
        }
    }