本文整理汇总了C#中System.Net.Mail.MailMessage.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.Mail.MailMessage.Dispose方法的具体用法?C# System.Net.Mail.MailMessage.Dispose怎么用?C# System.Net.Mail.MailMessage.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Mail.MailMessage
的用法示例。
在下文中一共展示了System.Net.Mail.MailMessage.Dispose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendEmail
/// <summary>
/// method to send email using SMTP server
/// </summary>
/// <param name="_FromEmail">From email address</param>
/// <param name="_FromName">From name</param>
/// <param name="_ToEmail">To email address</param>
/// <param name="_ToName">To name</param>
/// <param name="_Subject">Email subject</param>
/// <param name="_EmailBody">Email message body</param>
/// <param name="_IsBodyHtml">Is email message body HTML</param>
/// <param name="_Attachments">Email message file attachments</param>
/// <param name="_EmailServer">SMTP email server address</param>
/// <param name="_LoginName">SMTP email server login name</param>
/// <param name="_LoginPassword">SMTP email server login password</param>
/// <returns>TRUE if the email sent successfully, FALSE otherwise</returns>
private static bool SendEmail(string _FromEmail, string _FromName, string _ToEmail, string _ToName, string _Subject, string _EmailBody, bool _IsBodyHtml, string[] _Attachments, string _EmailServer, string _LoginName, string _LoginPassword)
{
try
{
// setup email header
System.Net.Mail.MailMessage _MailMessage = new System.Net.Mail.MailMessage();
// Set the message sender
// sets the from address for this e-mail message
_MailMessage.From = new System.Net.Mail.MailAddress(_FromEmail, _FromName);
// Sets the address collection that contains the recipients of this e-mail message
_MailMessage.To.Add(new System.Net.Mail.MailAddress(_ToEmail, _ToName));
// sets the message subject
_MailMessage.Subject = _Subject;
// sets the message body
_MailMessage.Body = _EmailBody;
// sets a value indicating whether the mail message body is in Html
// if this is false then ContentType of the Body content is "text/plain"
_MailMessage.IsBodyHtml = _IsBodyHtml;
// add all the file attachments if we have any
if (_Attachments != null && _Attachments.Length > 0)
foreach (string _Attachment in _Attachments)
_MailMessage.Attachments.Add(new System.Net.Mail.Attachment(_Attachment));
// SmtpClient Class Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP)
System.Net.Mail.SmtpClient _SmtpClient = new System.Net.Mail.SmtpClient(_EmailServer);
//Specifies how email messages are deliveredHere Email is sent through the network to an SMTP server
_SmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
// Some SMTP server will require that you first authenticate against the server
// Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication
System.Net.NetworkCredential _NetworkCredential = new System.Net.NetworkCredential(_LoginName, _LoginPassword);
_SmtpClient.UseDefaultCredentials = true;
_SmtpClient.Credentials = _NetworkCredential;
//Let's send it
_SmtpClient.Send(_MailMessage);
// Do cleanup
_MailMessage.Dispose();
_SmtpClient = null;
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
return false;
}
return true;
}
示例2: Send
public void Send(string MailTo, string Subject, string Text, string AttachFileName)
{
string svrName = DataAvail.WinUtils.Mail.MailSender.MAIL_PARAMS.ServerName;
string mailFrom = DataAvail.WinUtils.Mail.MailSender.MAIL_PARAMS.MailFrom;
if (!String.IsNullOrEmpty(svrName) && !String.IsNullOrEmpty(MailTo) && !String.IsNullOrEmpty(mailFrom))
{
string to = MailTo.Split(new char[] { ' ', ';', ',' }).Where(p => !string.IsNullOrEmpty(p)).Aggregate((p, n) => p + "," + n);
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(mailFrom, to, Subject, Text);
if (!string.IsNullOrEmpty(AttachFileName))
message.Attachments.Add(new System.Net.Mail.Attachment(AttachFileName));
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(svrName);
client.UseDefaultCredentials = true;
client.Send(message);
message.Dispose();
}
else
{
throw new System.Exception("ServerName, MailTo, MailFrom parameters must be defined");
}
}
示例3: EnviaEmail
public bool EnviaEmail(ParametroResumido pr, string sDestinatario,
string sRemetente,
string sCopia,
string sCopiaOculta,
string sAssunto,
string sTexto,
string sAnexo,
string sReservado)
{
//cria objeto com dados do e-mail
System.Net.Mail.MailMessage objEmail = new System.Net.Mail.MailMessage();
//remetente do e-mail
objEmail.From = new System.Net.Mail.MailAddress(sRemetente);
//destinatrios do e-mail
objEmail.To.Add(sDestinatario);
//enviar cpia para
if (!String.IsNullOrEmpty(sCopia))
{
objEmail.To.Add(sCopia);
}
//enviar cpia oculta para
if (!String.IsNullOrEmpty(sCopiaOculta))
{
objEmail.Bcc.Add(sCopiaOculta);
}
//prioridade do e-mail
objEmail.Priority = System.Net.Mail.MailPriority.Normal;
//formato do e-mail HTML (caso no queira HTML alocar valor false)
objEmail.IsBodyHtml = true;
//ttulo do e-mail
objEmail.Subject = sAssunto;
//corpo do e-mail
objEmail.Body = sTexto;
//Para evitar problemas de caracteres "estranhos", configuramos o charset para "ISO-8859-1"
objEmail.SubjectEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
objEmail.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
//cria objeto com os dados do SMTP
System.Net.Mail.SmtpClient objSmtp = new System.Net.Mail.SmtpClient();
#region login
string sHost = BuscaCampoTabela("HostSmtp", "PARAMETROS", " AND CODEMP = " + pr.CodEmp);
string sPorta = BuscaCampoTabela("PortaSmtp", "PARAMETROS", " AND CODEMP = " + pr.CodEmp);
string sSenha = BuscaCampoTabela("SenhaSmtp", "PARAMETROS", " AND CODEMP = " + pr.CodEmp);
objSmtp.Host = sHost;
objSmtp.Port = Convert.ToInt16(sPorta);
objSmtp.Credentials = new System.Net.NetworkCredential(sRemetente, sSenha);
#endregion
try
{
objSmtp.Send(objEmail);
objEmail.Dispose();
return true;
}
catch (Exception ex)
{
throw ex;
//return false;
}
}
示例4: 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++;
示例5: 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");
}