Motion.PlugIns.Alarm.EMail.SmtpMailSender.Send C# (CSharp) Method

Send() public method

public Send ( System m ) : void
m System
return void
        public void Send(System.Net.Mail.MailMessage m)
        {
            object userState = m;
            //mClient.Send(this.MailMessage);
            mClient.SendAsync(m, userState);
        }

Usage Example

示例#1
0
        public bool Alarm()
        {
            // create the mail message
            if (this.IsRunning == false)
            {
                this.mIsRunning = true;

                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                try
                {
                    if (this.mAttachImage == true && this.FeedImage != null)
                    {
                        FeedImage(this, null);
                    }
                    msg.SubjectEncoding = System.Text.Encoding.UTF8;
                    msg.BodyEncoding    = System.Text.Encoding.UTF8;
                    msg.IsBodyHtml      = false;
                    msg.Priority        = MailPriority.High;

                    msg.To.Add(this.ToAddress);
                    msg.From    = new MailAddress("*****@*****.**", this.Username, System.Text.Encoding.UTF8);
                    msg.Subject = string.Format(Translator.Instance.T("{0} 报警信息 ({1})"), MotionPreference.Instance.ProductFullName, DateTime.Now);
                    msg.Body    = string.Format(Translator.Instance.T("{0}报警邮件."), MotionPreference.Instance.ProductFullName);

                    if (this.mAttachImage == true)
                    {
                        lock (this)
                        {
                            if (mBitmap != null)
                            {
                                MemoryStream stm = new MemoryStream();
                                mBitmap.Save(stm, System.Drawing.Imaging.ImageFormat.Jpeg);
                                stm.Flush();
                                stm.Seek(0L, SeekOrigin.Begin);
                                Attachment img = new Attachment(stm, "alarm.jpg", "image/jpg");
                                msg.Attachments.Add(img);
                                //stm.Dispose();
                            }
                        }
                    }

                    mMailSender.Client.Host = this.SMTPAddress;
                    mMailSender.Client.Port = this.SMTPPort;
                    if (this.Username != null && this.Username.Length > 0)
                    {
                        mMailSender.Client.Credentials = new System.Net.NetworkCredential(this.Username, this.Password);
                    }
                    mMailSender.Client.Timeout   = this.Timeout * 1000;
                    mMailSender.Client.EnableSsl = this.SSL;

                    if (this.Log != null)
                    {
                        string s = string.Format(Translator.Instance.T("发送报警邮件. [{0}]."), msg.Subject);
                        Log(this, new LogEventArgs(LogLevel.LOG_INFO, s));
                    }
                    mMailSender.Send(msg);
                }
                catch (Exception ex)
                {
                    this.mIsRunning = false;
                    if (this.Log != null)
                    {
                        string s = string.Format(Translator.Instance.T("报警邮件发送失败. [{0}], {1}."), msg.Subject, ex.Message);
                        Log(this, new LogEventArgs(LogLevel.LOG_ERROR, s));
                    }
                }
            }
            return(true);
        }