本文整理汇总了C#中System.Net.Mail.SmtpClient.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SmtpClient.Dispose方法的具体用法?C# SmtpClient.Dispose怎么用?C# SmtpClient.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.SmtpClient
的用法示例。
在下文中一共展示了SmtpClient.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: sendPurchaseOrderToSupplier
public void sendPurchaseOrderToSupplier()
{
MailMessage purchaseOrderEmail = new MailMessage();
purchaseOrderEmail.To.Add(address);
purchaseOrderEmail.From = new MailAddress("[email protected]");
purchaseOrderEmail.Subject = "Purchase Order From Williams Engraving and Specialty Supplies";
Attachment attachment = new Attachment(path, MediaTypeNames.Application.Octet);
purchaseOrderEmail.Attachments.Add(attachment);
using (SmtpClient smtp = new SmtpClient())
{
try
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("[email protected]", "Pa$$word");
smtp.Send(purchaseOrderEmail);
}
catch (SmtpException ex)
{
smtp.Dispose();
}
finally
{
purchaseOrderEmail.Dispose();
smtp.Dispose();
}
}
}
示例2: SendEmailAsync
public static void SendEmailAsync(string email, string subject, string body)
{
try
{
string _email = ConfigurationManager.AppSettings["mailAccount"];
string _epass = ConfigurationManager.AppSettings["mailPassword"];
string _dispName = "Oleg Kaliuga";
MailMessage Message = new MailMessage();
Message.To.Add(email);
Message.From = new MailAddress(_email, _dispName);
Message.IsBodyHtml = true;
Message.Subject = subject;
Message.Body = body;
using (SmtpClient smtp = new SmtpClient())
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(_email, _epass);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.SendCompleted += (s, e) => { smtp.Dispose(); };
smtp.Send(Message);
}
}
catch (System.Exception ex)
{
throw ex;
}
}
示例3: SendEmail
public static void SendEmail(TSPlayer player, string email, User user)
{
MailMessage mail = new MailMessage(AccountRecovery.Config.EmailFrom, email);
SmtpClient client = new SmtpClient();
client.Timeout = 15000;
client.Host = AccountRecovery.Config.HostSMTPServer;
client.Port = AccountRecovery.Config.HostPort;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(AccountRecovery.Config.ServerEmailAddress, AccountRecovery.Config.ServerEmailPassword);
client.EnableSsl = true;
//client.ServicePoint.MaxIdleTime = 1;
mail.Subject = AccountRecovery.Config.EmailSubjectLine;
mail.Body = AccountRecovery.Config.EmailBodyLine;
mail.IsBodyHtml = AccountRecovery.Config.UseHTML;
string passwordGenerated = GeneratePassword(AccountRecovery.Config.GeneratedPasswordLength);
TShock.Users.SetUserPassword(user, passwordGenerated);
TShock.Log.ConsoleInfo("{0} has requested a new password succesfully.", user.Name);
mail.Body = string.Format(mail.Body.Replace("$NEW_PASSWORD", passwordGenerated));
mail.Body = string.Format(mail.Body.Replace("$USERNAME", user.Name));
client.Send(mail);
client.Dispose();
player.SendSuccessMessage("A new password has been generated and sent to {0} for {1}.", email, user.Name);
TShock.Log.ConsoleInfo("A new password has been generated and sent to {0} for {1}.", email, user.Name);
}
示例4: Send
public void Send(string subject, string text, string userMail)
{
SmtpClient smtpClient = null;
MailMessage message = null;
try
{
message = new MailMessage(new MailAddress(siteMail), new MailAddress(userMail))
{
Subject = subject,
Body = text
};
smtpClient = new SmtpClient(host, Convert.ToInt32(ConfigurationManager.AppSettings["port"]))
{
Credentials = new NetworkCredential(siteMail, passWord)
};
smtpClient.Send(message);
}
catch (SmtpException)
{
if (message != null)
message.Dispose();
if (smtpClient != null)
smtpClient.Dispose();
throw;
}
}
示例5: sendEmail
/// <summary>
/// A method to send and email. It accepts the sender of the email, a list
/// of recipients, the subject of the email, and the body of the email.
/// </summary>
/// <param name="sender"></param>
/// <param name="recipients"></param>
/// <param name="subject"></param>
/// <param name="body"></param>
public void sendEmail(string sender, List<string> recipients, string subject, StringBuilder body)
{
string username = "[email protected]";
string password = "2012SPP_user";
// Set the email parameters
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
System.Net.NetworkCredential credential = new System.Net.NetworkCredential(username, password);
client.Credentials = credential;
mail.From = new MailAddress(sender);
foreach (string recipient in recipients) {
mail.To.Add(recipient);
}
mail.Subject = subject;
mail.Body = body.ToString();
// Send the email
client.Send(mail);
// Clean up
client.Dispose();
mail.Dispose();
}
示例6: SendMail
public static Boolean SendMail(String receiver, String message)
{
if (_mailer == null)
{
lock (_lock)
{
if (_mailer == null)
{
_mailer = MailLoadConfig.Load();
}
}
}
//Prepare Message
MailMessage mail = new MailMessage();
mail.From = new MailAddress(_mailer.smtpFromEmail, _fromName);
mail.To.Add(receiver);
mail.Subject = "Registration Confirmation Email";
mail.Body = message;
//send the message
SmtpClient smtp = new SmtpClient(_mailer.SmtpServer);
smtp.Port = _mailer.SmtpPort;
smtp.Credentials = new NetworkCredential(_mailer.SmtpUserName, _mailer.SmtpPassWord);
smtp.EnableSsl = true;
smtp.Send(mail);
mail.Dispose();
smtp.Dispose();
return true;
}
示例7: SendEmailAsync
public async static TaskEventHandler SendEmailAsync(string email, string subject, string message)
{
try
{
var _email = "[email protected]";
var _epass = ConfigurationManager.AppSettings["EmailPassword"];
var _dispName = "Sean";
MailMessage myMessage = new MailMessage();
myMessage.To.Add(email);
myMessage.From = new MailAddress(_email, _dispName);
myMessage.Subject = subject;
myMessage.Body = message;
myMessage.IsBodyHtml = true;
using (SmtpClient smtp = new SmtpClient())
{
smtp.EnableSsl = true;
smtp.Host = "smtp.live.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(_email, _epass);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.SendCompleted += (s, e) => { smtp.Dispose(); };
await smtp.SendMailAsync(myMessage);
}
}
catch(Exception ex)
{
throw ex;
}
}
示例8: 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();
}
示例9: Send
public void Send()
{
try
{
var message = new MailMessage(Sender, Recipient, Subject, Body) { IsBodyHtml = true };
var smtp = new SmtpClient(_host, _port);
if (_user.Length > 0 && _pass.Length > 0)
{
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(_user, _pass);
smtp.EnableSsl = _ssl;
}
smtp.Send(message);
message.Dispose();
smtp.Dispose();
}
catch (Exception ex)
{
throw new Exception("Send Email Error: " + ex.Message);
}
}
示例10: SendMails
public void SendMails()
{
List<string> receivers = GetList();
MailMessage mail = new MailMessage();
Encoding encoding = Encoding.GetEncoding(28591);
SmtpClient client = new SmtpClient();
bool succes = false;
try {
mail.BodyEncoding = encoding;
mail.Subject = message.Subject;
mail.Body = message.Body;
mail.IsBodyHtml = message.Body.Contains("<") && message.Body.Contains(">");
if (message.Sender != null) mail.From = new MailAddress(message.Sender);
foreach (String recipient in receivers) {
mail.Bcc.Add(recipient.Trim());
}
client.Send(mail);
client.Dispose();
succes = true;
} catch (Exception e) {
ExecuteNonQuery("Insert into MessageExceptions values( " + messageID + ", '" + e.Message + "', '" + e.StackTrace + "')");
}
if (succes) RemoveFromQueue(receivers);
}
示例11: 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();
}
示例12: Send
public static void Send(string toAddress,string subject,string body,string attachmentPath)
{
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["UserPassword"])
};
Attachment attachment;
attachment = new Attachment(attachmentPath);
var emailAddress = ConfigurationManager.AppSettings["TestEmailAddress"];
if(string.IsNullOrEmpty(emailAddress))
{
emailAddress = toAddress;
}
var message = new MailMessage(ConfigurationManager.AppSettings["UserName"], emailAddress);
message.Subject = subject;
message.Body = body;
if (!string.IsNullOrEmpty(attachmentPath))
message.Attachments.Add(attachment);
smtp.Send(message);
message.Dispose();
smtp.Dispose();
}
示例13: sendBPMEmail
private void sendBPMEmail()
{
var dateAndTime = DateTime.Now;
var fromAddress = new MailAddress(this.fromTextBox.Text);
var toAddress = new MailAddress(this.toTextBox.Text);
var fromPassword = this.passwordTextBox.Text;
var subject = dateAndTime.ToString("yyyy MMMM dd") + ": Heart Rate";
var body = "My heart rate was " + this.bpm + " on " + dateAndTime.ToString("yyyy MMMM dd") + " at " + dateAndTime.ToString("hh:mm tt");
var client = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
EnableSsl = true,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
client.Send(message);
}
client.Dispose();
}
示例14: SendMail
/// <summary>
/// Sends the specified message to an SMTP server for delivery.
/// </summary>
/// <param name="from">The address of the sender of the e-mail message.</param>
/// <param name="to">The address of the recipient of the e-mail message.</param>
/// <param name="subject">The subject line for this e-mail message</param>
/// <param name="body">The message body.</param>
/// <param name="host">The name or IP address of the host used for SMTP transactions.</param>
public static void SendMail(string from, string to, string subject, string body, string host)
{
try
{
// Local variable declaration
var mMessage = new MailMessage();
var smtpClient = new SmtpClient();
// Set value form MailMessage
mMessage.From = new MailAddress(from);
mMessage.To.Add(new MailAddress(to));
mMessage.Subject = subject;
mMessage.IsBodyHtml = true;
mMessage.Body = body;
mMessage.Priority = MailPriority.Normal;
// Set value form SmtpClient
smtpClient.Host = host;
smtpClient.UseDefaultCredentials = true;
// Send
smtpClient.Send(mMessage);
// Dispose
mMessage.Dispose();
smtpClient.Dispose();
}
catch (Exception)
{
var message = MessageHelper.GetMessageFatal(
"F_MSG_00002", Messages.F_MSG_00002_T, Messages.F_MSG_00002_H);
throw new SysRuntimeException(message);
}
}
示例15: EnvoiMessage
public void EnvoiMessage(string destinataire, string cc, string message, string objet)
{
try
{
//Objet Mail
msg = new MailMessage();
// Expéditeur
msg.From = new MailAddress(this.adresseExpediteur, this.nomExpediteur);
// Destinataire(s)
foreach (String dest in destinataire.Split(';'))
{
msg.To.Add(new MailAddress(dest, dest));
}
// Destinataire(s) en copie
if (cc != null && cc != "")
{
foreach (String destcc in cc.Split(';'))
{
msg.CC.Add(new MailAddress(destcc));
}
}
//Objet du mail
msg.Subject = objet;
//Corps du mail
msg.Body = message;
// Configuration SMTP
client = new SmtpClient(SMTP, portSMTP);
client.EnableSsl = false;
client.Credentials = new NetworkCredential(SMTPUser, MDPSMTPUser);
// Envoi du mail
client.Send(msg);
//Tue le mail
msg.Dispose();
//Ferme la connexion au SMTP
client.Dispose();
}
catch (Exception ex)
{
//Tue le mail
if (msg != null)
{
msg.Dispose();
}
//Ferme la connexion au SMTP
if (client != null)
{
client.Dispose();
}
throw new Exception(ex.Message);
}
}