当前位置: 首页>>代码示例>>C#>>正文


C# MailMessage.Dispose方法代码示例

本文整理汇总了C#中System.Net.Mail.MailMessage.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.Dispose方法的具体用法?C# MailMessage.Dispose怎么用?C# MailMessage.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Mail.MailMessage的用法示例。


在下文中一共展示了MailMessage.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendMail

        public bool SendMail(string fromAddress, string toAddress, string subject, string body)
        {
            var mail = new MailMessage(fromAddress, toAddress, subject, body);
            mail.IsBodyHtml = true;
            bool success = false;
            var mailSettings = Helpers.GetConfigSectionGroup<MailSettingsSectionGroup>("system.net/mailSettings");
            var pickupDir = mailSettings != null &&
                            mailSettings.Smtp != null &&
                            mailSettings.Smtp.SpecifiedPickupDirectory != null ?
                            mailSettings.Smtp.SpecifiedPickupDirectory.PickupDirectoryLocation : null;

            if (!string.IsNullOrWhiteSpace(pickupDir) && !Directory.Exists(pickupDir))
            {
                Directory.CreateDirectory(pickupDir);
            }

            try
            {
                this._smtpClient.Send(mail);
                success = true;
                mail.Dispose();
            }
            catch (Exception ex)
            {
                mail.Dispose();
                Logger.Log(string.Format("An error occurred while trying to send a mail with subject {0} to {1}.", mail.Subject, mail.To), ex, LogLevel.Error);

                throw;
            }

            return success;
        }
开发者ID:StrixIT,项目名称:StrixIT.Platform,代码行数:32,代码来源:Mailer.cs

示例2: SendEmail

        public string SendEmail(string Recip, string Url)
        {

            System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage();
            try
            {

                var appSettings = ConfigurationManager.AppSettings;
                bool BSsl = Convert.ToBoolean(appSettings["Ssl_correo"]);


                MailAddress from = new MailAddress(appSettings["UserName_correo"], "IST");
                Email.To.Add(Recip);

                Email.Subject = appSettings["Subject"];
                Email.SubjectEncoding = System.Text.Encoding.UTF8;
                Email.Body = appSettings["Body"];
                Email.BodyEncoding = System.Text.Encoding.UTF8;
                Email.IsBodyHtml = false;
                Email.Attachments.Add(new Attachment(Url));
                Email.From = from;
                System.Net.Mail.SmtpClient cliente = new System.Net.Mail.SmtpClient();
                cliente.Port = Convert.ToInt16(appSettings["Puerto_correo"]);
                cliente.UseDefaultCredentials = true;
                cliente.Credentials = new System.Net.NetworkCredential(appSettings["UserName_correo"], appSettings["Password_correo"]);
                cliente.Host = appSettings["server_correo"];
                cliente.EnableSsl = BSsl;
                cliente.Send(Email);

                Email.Dispose();
                return "OK";
            }
            catch (SmtpException ex)
            {
                Email.Dispose();
                return (ex.Message + "Smtp.");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Email.Dispose();
                return "Sending Email Failed. Check Port Number.";
            }
            catch (InvalidOperationException Ex)
            {
                Email.Dispose();
                return "Sending Email Failed. Check Port Number.";
            }

           
        }
开发者ID:romscl,项目名称:istencuestas,代码行数:50,代码来源:Correo.cs

示例3: sendGmail

        public string sendGmail(string name, string userEmail, string value)
        {
            string reciverEmail = "[email protected]";
            string content = "'" + name + "' send a new message from AutoTutor Website\n\n Email address: " + userEmail + "\n\n Message content: " + value;
            MailMessage msg = new MailMessage();

            msg.From = new MailAddress(reciverEmail);
            msg.To.Add(reciverEmail);
            msg.Subject = "From AutoTutor Website! " + DateTime.Now.ToString();
            msg.Body = content;
            SmtpClient client = new SmtpClient();
            client.Host = "smtp.gmail.com";
            client.Port = 587;
            client.EnableSsl = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(reciverEmail, "TNMemFIT410");
            client.Timeout = 20000;
            try
            {
                client.Send(msg);
                return "Mail has been successfully sent!";
            }
            catch (Exception ex)
            {
                return "Fail Has error" + ex.Message;
            }
            finally
            {
                msg.Dispose();
            }
        }
开发者ID:qinyucheng,项目名称:sendEmail,代码行数:32,代码来源:sendEmailController.cs

示例4: Send

        // Отправка сообщения на почту
        public static async Task Send(Request request)
        {
            var body = "<p>Саня, на нашем сайте заявка от человека с именем, {0} {1}!</p><pЕму можно позвонить по номеру:{2}<br>Его почта: {3}</p>";
            var message = new MailMessage();
            message.To.Add(new MailAddress(MailRecipient));  // replace with valid value 
            message.From = new MailAddress(MailSender);  // replace with valid value
            message.Subject = "Вы оставили заявку на нашем сайте";
            message.Body = string.Format(body, request.FirstName, request.LastName, request.PhoneNumber, request.MiddleName);

            message.IsBodyHtml = true;

            using (var smtp = new SmtpClient())
            {
                var credential = new NetworkCredential
                {
                    UserName = MailSender,  // replace with valid value
                    Password = "SmolinaBreakBeat12357895"  // replace with valid value
                };

                smtp.Credentials = credential;
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                await smtp.SendMailAsync(message);
                message.Dispose();
            }
        }
开发者ID:alexanderloser,项目名称:AceInTheHole,代码行数:28,代码来源:Email.cs

示例5: SendMessage

 public bool SendMessage(string from, string to,
      string subject, string body)
 {
     MailMessage mailMessage = null;
     bool isSent = false;
     try
     {
         mailMessage = new MailMessage(from, to, subject, body);
         mailMessage.DeliveryNotificationOptions = 
                DeliveryNotificationOptions.OnFailure;
         // Send it
         
         _client.Send(mailMessage);
         isSent = true;
     }
     // Catch any errors, these should be logged 
     catch (Exception ex)
     {
         
     }
     finally
     {
         mailMessage.Dispose();
     }
     return isSent;
 }
开发者ID:xmendoza,项目名称:BeerDrinkin,代码行数:26,代码来源:EmailClient.cs

示例6: SendForm

        public ActionResult SendForm(EmailInfoModel emailInfo)
        {
            try
            {
                MailMessage msg = new MailMessage(CloudConfigurationManager.GetSetting("EmailAddr"), "[email protected]");
                var smtp = new SmtpClient("smtp.gmail.com", 587)
                {

                    Credentials = new NetworkCredential(CloudConfigurationManager.GetSetting("EmailAddr"), CloudConfigurationManager.GetSetting("EmailKey")),
                    EnableSsl = true
                };

                StringBuilder sb = new StringBuilder();
                msg.To.Add("[email protected]");
                msg.Subject = "Contact Us";
                msg.IsBodyHtml = false;

                sb.Append(Environment.NewLine);
                sb.Append("Email: " + emailInfo.Email);
                sb.Append(Environment.NewLine);
                sb.Append("Message: " + emailInfo.Message);

                msg.Body = sb.ToString();

                smtp.Send(msg);
                msg.Dispose();
                return RedirectToAction("Contact", "Home");
            }
            catch (Exception)
            {
                return View("Error");
            }
        }
开发者ID:JackTLi,项目名称:JTLPortalV2,代码行数:33,代码来源:HomeController.cs

示例7: SendMail

 /// <summary>
 /// Sends an email
 /// </summary>
 /// <param name="Message">The body of the message</param>
 public void SendMail(string Message)
 {
     try
     {
         System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
         char[] Splitter = { ',' };
         string[] AddressCollection = to.Split(Splitter);
         for (int x = 0; x < AddressCollection.Length; ++x)
         {
             message.To.Add(AddressCollection[x]);
         }
         message.Subject = subject;
         message.From = new System.Net.Mail.MailAddress((from));
         message.Body = Message;
         message.Priority = Priority_;
         message.SubjectEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
         message.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
         message.IsBodyHtml = true;
         if (Attachment_ != null)
         {
             message.Attachments.Add(Attachment_);
         }
         System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(Server,Port);
         if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
         {
             smtp.Credentials = new System.Net.NetworkCredential(UserName,Password);
         }
         smtp.Send(message);
         message.Dispose();
     }
     catch (Exception e)
     {
         throw new Exception(e.ToString());
     }
 }
开发者ID:summer-breeze,项目名称:ChengGouHui,代码行数:39,代码来源:EmailSender.cs

示例8: SendEmail

        public static void SendEmail(EmailSenderData emailData)
        {
            MailMessage mail = new MailMessage();
            SmtpClient smtpServer = new SmtpClient(emailData.SmtpClient);
            smtpServer.Port = 25;
            mail.From = new MailAddress(emailData.FromEmail);

            foreach (string currentEmail in emailData.Emails)
            {
                mail.To.Add(currentEmail);
            }
            mail.Subject = emailData.Subject;
            mail.IsBodyHtml = true;
            mail.Body = emailData.EmailBody;

            if (emailData.AttachmentPath != null)
            {                
                foreach (string currentPath in emailData.AttachmentPath)
                {
                    Attachment  attachment = new Attachment(currentPath);
                    mail.Attachments.Add(attachment);                    
                }               
                smtpServer.Send(mail);
                DisposeAllAttachments(mail);
            }
            else
            {
                smtpServer.Send(mail);
            }

            mail.Dispose();
            smtpServer.Dispose();
        }
开发者ID:kennedykinyanjui,项目名称:Projects,代码行数:33,代码来源:EmailSender.cs

示例9: SendMailMessage

        /// <summary>
        /// Sends a MailMessage object using the SMTP settings.
        /// </summary>
        public static void SendMailMessage(MailMessage message,string smtpServer,string smtpUserName,string smtpPassword,int smtpServerPort,bool enableSsl)
        {
            if (message == null)
                throw new ArgumentNullException("message");

            try
            {
                message.IsBodyHtml = true;
                message.BodyEncoding = Encoding.UTF8;
                SmtpClient smtp = new SmtpClient(smtpServer);
                // don't send credentials if a server doesn't require it,
                // linux smtp servers don't like that
                if (!string.IsNullOrEmpty(smtpUserName))
                {
                    smtp.Credentials = new System.Net.NetworkCredential(smtpUserName, smtpPassword);
                }
                smtp.Port =smtpServerPort;
                smtp.EnableSsl = enableSsl;
                smtp.Send(message);
                OnEmailSent(message);
            }
            catch (SmtpException)
            {
                OnEmailFailed(message);
            }
            finally
            {
                // Remove the pointer to the message object so the GC can close the thread.
                message.Dispose();
                message = null;
            }
        }
开发者ID:mamboer,项目名称:itask,代码行数:35,代码来源:Utils.mail.cs

示例10: Send

 public void Send(IEmailContent email)
 {
     MailMessage mailmsg = new MailMessage();
     IEnumerable<MailAddress> rec = email.GetReceivers();
     if (rec == null || !rec.Any()) return;
     rec.Each(mailmsg.To.Add);
     var cc = email.GetCCReceivers();
     if (cc != null)
     {
         cc.Each(mailmsg.CC.Add);
     }
     var bcc = email.GetBCCReceivers();
     if (bcc != null)
     {
         bcc.Each(mailmsg.Bcc.Add);
     }
     var attachments = email.GetAttachments();
     if (attachments != null)
     {
         attachments.Each(mailmsg.Attachments.Add);
     }
     mailmsg.Subject = email.GetSubject();
     mailmsg.Body = email.GetBody();
     mailmsg.BodyEncoding = Encoding.UTF8;
     mailmsg.IsBodyHtml = email.IsBodyHtml();
     mailmsg.From = email.GetSender();
     mailmsg.Priority = MailPriority.Normal;
     var smtp = email.GetSmtpClient();
     smtp.Send(mailmsg);
     mailmsg.Attachments.Each(m => m.Dispose());
     mailmsg.Dispose();
     smtp.Dispose();
     email.OnSendComplete(email);
 }
开发者ID:hardCTE,项目名称:EasyFrameWork,代码行数:34,代码来源:EmailSender.cs

示例11: SendCrashReport

        public static void SendCrashReport(string body, string type)
        {
            try
            {
                string destfile = Path.Combine(Path.GetTempPath(), "error_report.zip");
                if (File.Exists(destfile))
                    File.Delete(destfile);

                using (var zip = new ZipFile(destfile))
                {
                        zip.AddFile(ServiceProvider.LogFile, "");
                        zip.Save(destfile);
                }
                var client = new MailgunClient("digicamcontrol.mailgun.org", "key-6n75wci5cpuz74vsxfcwfkf-t8v74g82");
                var message = new MailMessage("[email protected]", "[email protected]")
                                  {
                                      Subject = (type ?? "Log file"),
                                      Body = "Client Id" + (ServiceProvider.Settings.ClientId ?? "") + "\n" + body,
                                  };
                message.Attachments.Add(new Attachment(destfile));

                client.SendMail(message);
                message.Dispose();
            }
            catch (Exception )
            {

            }
        }
开发者ID:brunoklein99,项目名称:nikon-camera-control,代码行数:29,代码来源:HelpProvider.cs

示例12: SendEmail

        /// <summary>
        /// Sends the email.
        /// </summary>
        /// <param name="emailData">The email data.</param>
        public static void SendEmail(EmailMessageData emailData)
        {
            MailMessage mail = new MailMessage();
            SmtpClient smtpServer = new SmtpClient(CurrentSmtpClient);
            smtpServer.Port = CurrentSmtpClientPort;

            mail.From = new MailAddress(emailData.FromEmail);

            foreach (string currentEmail in emailData.Emails)
            {
                mail.To.Add(currentEmail);
            }

            mail.Subject = emailData.Subject;
            mail.IsBodyHtml = true;
            mail.Body = emailData.EmailBody;

            AddAttachmentsToEmail(emailData, mail);

            smtpServer.Send(mail);

            DisposeAllAttachments(mail);
            mail.Dispose();
            smtpServer.Dispose();
        }
开发者ID:kennedykinyanjui,项目名称:Projects,代码行数:29,代码来源:EmailSender.cs

示例13: SendMessage

        public static bool SendMessage(string emailFrom, string emailTo,string login,string password)
        {
            bool result = true;
            try
            {
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress(emailFrom);
                mail.To.Add(new MailAddress(emailTo));
                mail.Subject = "Subject";
                mail.Body = "Text";

                SmtpClient client = new SmtpClient();
                client.Host = "smtp.mail.ru";
                client.Port = 587;
                client.EnableSsl = true;
                client.Credentials = new NetworkCredential(login, password);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.Send(mail);
                mail.Dispose();
            }
            catch (Exception e)
            {
                result = false;
                //throw new Exception("Mail.Send: " + e.Message);
            }
            return result;
        }
开发者ID:MaxRudenko,项目名称:social-network,代码行数:27,代码来源:MailMessanger.cs

示例14: SendEmail

        public static void SendEmail(string emailType, string emailSubject, string emailBody,string emailAttachFileName)
        {
            if (Properties.Settings.Default.EmailEnabled)
            {
                System.Net.Mail.MailMessage message = null;
                try
                {
                    string emailFrom = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + "_" + System.Environment.MachineName + "@" + Properties.Settings.Default.EmailSenderDomain;
                    string emailTo = Properties.Settings.Default.EmailNotifyAddresses;
                    emailSubject = emailType + " - " + emailSubject;
                    emailBody = "Application:  " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name +Environment.NewLine + Environment.NewLine +
                                 emailType+" Message: "+ Environment.NewLine + emailBody;
                    message = new System.Net.Mail.MailMessage(emailFrom,emailTo, emailSubject, emailBody);
                    if (emailAttachFileName != null && emailAttachFileName.Trim() != "")
                    {
                        message.Attachments.Add(new Attachment(emailAttachFileName));
                    }

                    SmtpClient client = new SmtpClient();
                    client.Host = Properties.Settings.Default.EmailHost;
                    client.Port = Properties.Settings.Default.EmailPort;
                    client.Send(message);
                }
                finally
                {
                    message.Dispose();
                }
            }
        }
开发者ID:Amphora2015,项目名称:DemoTest,代码行数:29,代码来源:MailUtils.cs

示例15: SendMessage

        private static bool SendMessage(string from, string to, string subject, string body)
        {
            MailMessage mm = null;
            bool isSent = false;
            try
            {
                // Create our message
                mm = new MailMessage(from, to, subject, body);
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                // Send it
                Client.Send(mm);
                isSent = true;
            }
            // Catch any errors, these should be logged and dealt with later
            catch (Exception ex)
            {
                // If you wish to log email errors,
                // add it here...
                var exMsg = ex.Message;
            }
            finally
            {
                mm.Dispose();
            }

            return isSent;
        }
开发者ID:the404,项目名称:xyz,代码行数:28,代码来源:MailClient.cs


注:本文中的System.Net.Mail.MailMessage.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。