本文整理汇总了C#中System.Net.Mail.SmtpClient.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.Mail.SmtpClient.Dispose方法的具体用法?C# System.Net.Mail.SmtpClient.Dispose怎么用?C# System.Net.Mail.SmtpClient.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.SmtpClient
的用法示例。
在下文中一共展示了System.Net.Mail.SmtpClient.Dispose方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
public static bool Send(string from, string subject, string body)
{
System.Net.Mail.SmtpClient s = null;
try
{
s = new System.Net.Mail.SmtpClient("smtp.live.com", 587);
s.EnableSsl = true;
s.UseDefaultCredentials = false;
s.Credentials = new System.Net.NetworkCredential("seu email", "sua senha");
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(
new System.Net.Mail.MailAddress("seu email"),
new System.Net.Mail.MailAddress("seu email"));
message.Body = "De: " + from + "\n" + body;
message.BodyEncoding = Encoding.UTF8;
message.Subject = subject;
message.SubjectEncoding = Encoding.UTF8;
s.Send(message);
s.Dispose();
return true;
}
catch
{
return false;
}
finally
{
if (s != null)
s.Dispose();
}
}
示例2: Send
public static bool Send(string nome, string from, string subject, string mensagem)
{
System.Net.Mail.SmtpClient s = null;
try
{
s = new System.Net.Mail.SmtpClient("smtp.live.com", 587);
s.EnableSsl = true;
s.UseDefaultCredentials = false;
s.Credentials = new System.Net.NetworkCredential("[email protected]", "[email protected]$angue");
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(
new System.Net.Mail.MailAddress(from),
new System.Net.Mail.MailAddress("[email protected]"));
message.Body = "De: " +nome+ "\n"+ "Email: "+from + "\n" + "\n"+ "Mensagem: "+"\n"+mensagem;
message.BodyEncoding = Encoding.UTF8;
message.Subject = subject;
message.SubjectEncoding = Encoding.UTF8;
s.Send(message);
s.Dispose();
return true;
}
catch
{
return false;
}
finally
{
if (s != null)
s.Dispose();
}
}
示例3: SendSenha
public static bool SendSenha(string from, string to, string subject, string mensagem)
{
System.Net.Mail.SmtpClient s = null;
try
{
s = new System.Net.Mail.SmtpClient("smtp.live.com", 587);
s.EnableSsl = true;
s.UseDefaultCredentials = false;
s.Credentials = new System.Net.NetworkCredential("c[email protected]", "Projeto032015");
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(
new System.Net.Mail.MailAddress(from),
new System.Net.Mail.MailAddress(to));
message.Body = mensagem;
message.BodyEncoding = Encoding.UTF8;
message.Subject = subject;
message.SubjectEncoding = Encoding.UTF8;
s.Send(message);
s.Dispose();
return true;
}
catch
{
return false;
}
finally
{
if (s != null)
s.Dispose();
}
}
示例4: sendEmailWithSmtpServer
private static void sendEmailWithSmtpServer( Configuration.InstallationStandard.SmtpServer smtpServer, EmailMessage message )
{
// We used to cache the SmtpClient object. It turned out not to be thread safe, so now we create a new one for every email.
var smtpClient = new System.Net.Mail.SmtpClient();
try {
if( smtpServer != null ) {
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.Host = smtpServer.Server;
if( smtpServer.PortSpecified )
smtpClient.Port = smtpServer.Port;
if( smtpServer.Credentials != null ) {
smtpClient.Credentials = new System.Net.NetworkCredential( smtpServer.Credentials.UserName, smtpServer.Credentials.Password );
smtpClient.EnableSsl = true;
}
}
else {
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
var pickupFolderPath = EwlStatics.CombinePaths( ConfigurationStatics.RedStaplerFolderPath, "Outgoing Dev Mail" );
Directory.CreateDirectory( pickupFolderPath );
smtpClient.PickupDirectoryLocation = pickupFolderPath;
}
using( var m = new System.Net.Mail.MailMessage() ) {
m.From = message.From.ToMailAddress();
addAddressesToMailAddressCollection( message.ReplyToAddresses, m.ReplyToList );
addAddressesToMailAddressCollection( message.ToAddresses, m.To );
addAddressesToMailAddressCollection( message.CcAddresses, m.CC );
addAddressesToMailAddressCollection( message.BccAddresses, m.Bcc );
m.Subject = message.Subject;
foreach( var i in message.CustomHeaders )
m.Headers.Add( i.Item1, i.Item2 );
m.Body = htmlToPlainText( message.BodyHtml );
// Add an alternate view for the HTML part.
m.AlternateViews.Add(
System.Net.Mail.AlternateView.CreateAlternateViewFromString( message.BodyHtml, new System.Net.Mime.ContentType( ContentTypes.Html ) ) );
foreach( var attachment in message.Attachments )
m.Attachments.Add( attachment.ToAttachment() );
try {
smtpClient.Send( m );
}
catch( System.Net.Mail.SmtpException e ) {
throw new EmailSendingException( "Failed to send an email message using an SMTP server.", e );
}
}
}
finally {
// Microsoft's own dispose method fails to work if Host is not specified, even though Host doesn't need to be specified for operation.
if( !string.IsNullOrEmpty( smtpClient.Host ) )
smtpClient.Dispose();
}
}
示例5: sendEmailWithSmtpServer
private static void sendEmailWithSmtpServer( SmtpServer smtpServer, EmailMessage message )
{
// We used to cache the SmtpClient object. It turned out not to be thread safe, so now we create a new one for every email.
var smtpClient = new System.Net.Mail.SmtpClient();
try {
if( smtpServer != null ) {
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.Host = smtpServer.Server;
if( smtpServer.PortSpecified )
smtpClient.Port = smtpServer.Port;
if( smtpServer.Credentials != null ) {
smtpClient.Credentials = new System.Net.NetworkCredential( smtpServer.Credentials.UserName, smtpServer.Credentials.Password );
smtpClient.EnableSsl = true;
}
}
else {
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
var pickupFolderPath = EwlStatics.CombinePaths( ConfigurationStatics.RedStaplerFolderPath, "Outgoing Dev Mail" );
Directory.CreateDirectory( pickupFolderPath );
smtpClient.PickupDirectoryLocation = pickupFolderPath;
}
using( var m = new System.Net.Mail.MailMessage() ) {
message.ConfigureMailMessage( m );
try {
smtpClient.Send( m );
}
catch( System.Net.Mail.SmtpException e ) {
throw new EmailSendingException( "Failed to send an email message using an SMTP server.", e );
}
}
}
finally {
// Microsoft's own dispose method fails to work if Host is not specified, even though Host doesn't need to be specified for operation.
if( !string.IsNullOrEmpty( smtpClient.Host ) )
smtpClient.Dispose();
}
}
示例6: sendEmailWithSendGrid
private static void sendEmailWithSendGrid( SendGrid sendGrid, EmailMessage message )
{
// We want this method to use the SendGrid API (https://github.com/sendgrid/sendgrid-csharp), but as of 20 June 2014 it looks like the SendGrid Web API
// does not support CC recipients!
// We used to cache the SmtpClient object. It turned out not to be thread safe, so now we create a new one for every email.
var smtpClient = new System.Net.Mail.SmtpClient( "smtp.sendgrid.net", 587 );
try {
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.Credentials = new System.Net.NetworkCredential( sendGrid.UserName, sendGrid.Password );
using( var m = new System.Net.Mail.MailMessage() ) {
message.ConfigureMailMessage( m );
try {
smtpClient.Send( m );
}
catch( System.Net.Mail.SmtpException e ) {
throw new EmailSendingException( "Failed to send an email message using SendGrid.", e );
}
}
}
finally {
smtpClient.Dispose();
}
}
示例7: Send
/// <summary>
/// 邮件的发送;发送成功返回null,失败返回失败原因
/// </summary>
/// <returns>发送失败则返回错误信息</returns>
public string Send()
{
mSmtpClient = new System.Net.Mail.SmtpClient();
try
{
if (mMailMessage != null)
{
//mSmtpClient.Host = "smtp." + mMailMessage.From.Host;
mSmtpClient.Host = this.mSenderServerHost;
mSmtpClient.Port = this.mSenderPort;
mSmtpClient.UseDefaultCredentials = false;
mSmtpClient.EnableSsl = this.mEnableSsl;
if (this.mEnablePwdAuthentication)
{
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
//mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
//NTLM: Secure Password Authentication in Microsoft Outlook Express
mSmtpClient.Credentials = nc.GetCredential(mSmtpClient.Host, mSmtpClient.Port, "NTLM");
}
else
{
mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
}
mSmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
mSmtpClient.Send(mMailMessage);
}
}
catch(Exception ex)
{
return ex.Message;
}
finally
{
mSmtpClient.Dispose();
}
return null;
}
示例8: SendEmailNotification
public static void SendEmailNotification(List<System.Net.Mail.MailMessage> emails)
{
if (!Lib.Utility.Common.IsNullOrEmptyList(emails))
{
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["smtphost"]);
try
{
foreach (System.Net.Mail.MailMessage obj_message in emails)
{
smtp.Send(obj_message);
}
smtp.Dispose();
}
catch (Exception exc)
{
throw exc;
}
finally
{
smtp.Dispose();
}
}
}
示例9: RunMarimo
//.........这里部分代码省略.........
Debug.WriteLine("send: " + val_int[getadr_i(rowlist[1])].Val.ToString());
}
if (rowlist[1].Split('_')[0].Equals("f")) {
Debug.WriteLine("send: " + val_float[getadr_f(rowlist[1])].Val.ToString());
}
} else {
Debug.WriteLine("send: " + rowlist[1]);
}
// CPU温度 ("send,get,temp")
} else if (rowlist.Length == 3) {
Debug.WriteLine("send: " + getTemp());
// GPIO値 ("send,get,gpio,1")
} else if (rowlist.Length == 4) {
Debug.WriteLine("send: " + getGPIO(int.Parse(rowlist[3])));
}
row++;
// mail送信("mail,[email protected],件名,本文")
} else if (rowlist[0].Equals("mail")) {
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(
"[email protected]", rowlist[1],
rowlist[2], rowlist[3]);
System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
sc.Credentials = new System.Net.NetworkCredential("[email protected]", "MarimoCats");
sc.EnableSsl = true;
sc.Send(msg);
msg.Dispose();
sc.Dispose();
row++;
// break文("break")
} else if (rowlist[0].Equals("break")) {
while (true) {
row++;
if (codelist[row].Split(',')[0].Equals("endw")) {
row++;
break;
}
}
// continue文("continue")
} else if (rowlist[0].Equals("continue")) {
while (true) {
row++;
if (codelist[row].Split(',')[0].Equals("endw")) {
row = int.Parse(codelist[row].Split(',')[1]);
break;
}
}
// if文に入った場合のelse
} else if (rowlist[0].Equals("else")) {
while (true) {
row++;
示例10: SendMail
static void SendMail(string subject, string text, string destination) {
Console.WriteLine("SendMail_Start");
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(
"[email protected]", destination,
subject, text);
System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
sc.Credentials = new System.Net.NetworkCredential("[email protected]", "MarimoCats");
sc.EnableSsl = true;
sc.Send(msg);
msg.Dispose();
sc.Dispose();
Console.WriteLine("SendMail_End");
}
示例11: SendEmail
public void SendEmail(string pSubject, string pDetall, string pEmailDestination)
{
System.Net.Mail.MailMessage vMmsg = new System.Net.Mail.MailMessage();
string vEmailServer = System.Configuration.ConfigurationManager.AppSettings["EMAILSERVER"];
string vEmailPsw = System.Configuration.ConfigurationManager.AppSettings["EMAILPSW"];
string vHost = System.Configuration.ConfigurationManager.AppSettings["EMAILHOST"];
vMmsg.To.Add(pEmailDestination);
string vSubject = pSubject;
vMmsg.Subject = vSubject;
vMmsg.SubjectEncoding = System.Text.Encoding.UTF8;
vMmsg.Body = pDetall;
vMmsg.BodyEncoding = System.Text.Encoding.UTF8;
vMmsg.IsBodyHtml = false;
vMmsg.From = new System.Net.Mail.MailAddress(vEmailServer);
System.Net.Mail.SmtpClient vCliente = new System.Net.Mail.SmtpClient();
vCliente.Credentials =
new System.Net.NetworkCredential(vEmailServer, vEmailPsw);
vCliente.Host = vHost;
try
{
vCliente.Send(vMmsg);
vCliente.Dispose();
}
catch (System.Net.Mail.SmtpException ex)
{
}
}
示例12: SendSenha
public static bool SendSenha(string nome, string from, string to, string subject, string mensagem)
{
System.Net.Mail.SmtpClient s = null;
try
{
s = new System.Net.Mail.SmtpClient("smtp.live.com", 587);
s.EnableSsl = true;
s.UseDefaultCredentials = false;
s.Credentials = new System.Net.NetworkCredential("[email protected]", "bandtec1234");
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(
new System.Net.Mail.MailAddress(from),
new System.Net.Mail.MailAddress(to));
message.Body = mensagem;
message.BodyEncoding = Encoding.UTF8;
message.Subject = subject;
message.SubjectEncoding = Encoding.UTF8;
s.Send(message);
s.Dispose();
return true;
}
catch
{
return false;
}
finally
{
if (s != null)
s.Dispose();
}
}