本文整理汇总了C#中SmtpClient.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SmtpClient.Dispose方法的具体用法?C# SmtpClient.Dispose怎么用?C# SmtpClient.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmtpClient
的用法示例。
在下文中一共展示了SmtpClient.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmailAlert
public static bool EmailAlert(string to_add, string from_add, string em_sub, string em_bd, string smtp_server = null, string sAttachment = null)
{
int i = 0;
string[] sTempA = null;
SmtpClient SmtpMail = new SmtpClient();
MailMessage MailMsg = new MailMessage();
sTempA = to_add.Split(',');
try
{
for (i = 0; i < (sTempA.Length -1); i++)
{
MailMsg.To.Add(new MailAddress(sTempA[i]));
}
MailMsg.From = new MailAddress(from_add);
MailMsg.Subject = em_sub.Trim();
MailMsg.Body = em_bd.Trim() + Environment.NewLine;
if (sAttachment != null)
{
Attachment MsgAttach = new Attachment(sAttachment);
MailMsg.Attachments.Add(MsgAttach);
if (smtp_sender == null)
{
// default
SmtpMail.Host = "";
}
else
{
SmtpMail.Host = smtp_sender;
}
SmtpMail.Send(MailMsg);
MsgAttach.Dispose();
}
else
{
SmtpMail.Host = smtp_sender;
SmtpMail.Send(MailMsg);
}
return true;
}
catch (Exception ex)
{
sTempA = null;
SmtpMail.Dispose();
MailMsg.Dispose();
//Console.WriteLine(ex);
return false;
}
}
示例2: TextAlert
public static bool TextAlert(string body, string textAlert = null)
{
// If established:
if (textAlert == null)
{
textAlert = ""; // Default
}
bool check = false;
string smtp_sender = "";
string from = "";
SmtpClient smtpcl = new SmtpClient(smtp_sender);
if (body.Count() > 140)
{
string b;
int start = 0;
float bodycount = (body.Count() / 140);
if (((body.Count() % 140) != 0))
{
for (int i = 1; i <= (bodycount + 1); i++)
{
if (i == (bodycount + 1))
{
b = body.Substring(start, (body.Count() - start));
}
else
{
b = body.Substring(start, 140);
}
try
{
smtpcl.Send(from, textAlert, "", b);
check = true;
}
catch (Exception ex)
{
Console.WriteLine("Text alert failed. Error: " + ex.ToString());
}
start = start + 140;
}
}
else
{
for (int i = 1; i <= bodycount; i++)
{
b = body.Substring(start, 140);
try
{
smtpcl.Send(from, textAlert, "", b);
check = true;
}
catch (Exception ex)
{
Console.WriteLine("Text alert failed. Error: " + ex.ToString());
}
start = start + 140;
}
}
}
else
{
try
{
smtpcl.Send(from, textAlert, "", body);
check = true;
}
catch (Exception ex)
{
Console.WriteLine("Text alert failed. Error: " + ex.ToString());
}
}
smtpcl.Dispose();
return check;
}