如何使用c#

时间:2019-03-27 14:54:31

标签: c# model-view-controller upload

我想查看电子邮件是否已正确发送 我尝试了以下测试案例。 1.如果电子邮件ID正确,即xyx@gmail.com,则电子邮件将正确发送 2.如果电子邮件ID不正确,即xyxgmail.com 我们如何检查电子邮件是否已发送。

    public int CallAsynSendMail_ServiceNow(string EmailFrom_ServiceNowHelpdek, HttpPostedFileBase AttachementsList)
    {
        try
        {
            System.Net.Mail.MailMessage Mailobj = new System.Net.Mail.MailMessage();
            var Host = WebConfigurationManager.AppSettings["EmailHost"].ToString();
            var _From = EmailFrom_ServiceNowHelpdek;
            Mailobj.Subject = this.Subject;
            Mailobj.Body = this.Body;
            Mailobj.IsBodyHtml = this.IsBodyHtml;
            if (AttachementsList != null)
            {
                string fileName = Path.GetFileName(AttachementsList.FileName);
                Mailobj.Attachments.Add(new Attachment(AttachementsList.InputStream, fileName));
            }
            // if (this.Attachment != null && this.Attachment != string.Empty)
            //  {
            //     Mailobj.Attachments.Add(new Attachment(this.Attachment));
            //   }
            if (this.To != null)
            {
                string[] arrTo = this.To.Split(';');
                foreach (var To in arrTo)
                {
                    Mailobj.To.Add(To);
                }
            }
            if (this.CC != null)
            {
                string[] arrCC = this.CC.Split(';');
                foreach (var CC in arrCC)
                {
                    Mailobj.CC.Add(CC);
                }
            }

            Object state = Mailobj;

            Mailobj.From = this.From ?? new MailAddress(_From);
            var smtpClient = new SmtpClient(Host.ToString());
            smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);

            smtpClient.SendAsync(Mailobj, state);
            return 1;
        }
        catch (Exception Ex)
        {
            return 0;
            throw Ex;
        }

    }

0 个答案:

没有答案