本文整理汇总了C#中MailMessage.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MailMessage.Dispose方法的具体用法?C# MailMessage.Dispose怎么用?C# MailMessage.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MailMessage
的用法示例。
在下文中一共展示了MailMessage.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMail
static void SendMail()
{
try
{
// Declare msg as MailMessage instance
MailMessage msg = new MailMessage("[email protected]", "[email protected]", "Test subject", "Test body");
SmtpClient client = GetSmtpClient2();
object state = new object();
IAsyncResult ar = client.BeginSend(msg, Callback, state);
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
string answer = Console.ReadLine();
// If the user canceled the send, and mail hasn't been sent yet,
if (answer != null && answer.StartsWith("c"))
{
client.CancelAsyncOperation(ar);
}
msg.Dispose();
Console.WriteLine("Goodbye.");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
示例2: Send
public static Boolean Send(string Destinatario, string Assunto, string Mensagem)
{
try
{
MailMessage mm = new MailMessage();
mm.IsBodyHtml = true;
mm.From = new MailAddress("[email protected]");
mm.To.Add(Destinatario);
mm.Subject = Assunto;
mm.Body = Mensagem;
SmtpClient sc = new SmtpClient("mail.neutoncorretor.com.br", 587);
sc.UseDefaultCredentials = false;
sc.Credentials = new NetworkCredential("[email protected]", "@Pipoca16");
sc.EnableSsl = false;
sc.Send(mm);
mm.Dispose();
return true;
}
catch (Exception)
{
return false;
}
}
示例3: sendMail
public void sendMail(string fsSubject,string fsBody,string fsToEmail)
{
MailMessage mailmsg = new MailMessage();
SmtpClient smtpclient = new SmtpClient();
StringBuilder strBuild = new StringBuilder();
smtpclient.UseDefaultCredentials = false;
smtpclient.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Admin"],
ConfigurationManager.AppSettings["Password"]);
smtpclient.Host = ConfigurationManager.AppSettings["SmtpServer"];
smtpclient.Port = Convert.ToInt32(ConfigurationManager.AppSettings["PortNo"]);
smtpclient.EnableSsl = false;
mailmsg.From = new MailAddress("[email protected]", "callms");
//
// TODO: Add constructor logic here
mailmsg.Subject = fsSubject;
mailmsg.IsBodyHtml = true;
mailmsg.BodyEncoding = System.Text.Encoding.UTF8;
mailmsg.Body = fsBody;
smtpclient.Send(mailmsg);
mailmsg.Dispose();
}
示例4: 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();
}
示例5: sendEmail
public void sendEmail(string recipID, string msgBody)
{
ArrayList msgList = new ArrayList();
msgList.Clear();
msgList.Add(recipID);
foreach (string item in msgList)
{
try
{
MailMessage message = new MailMessage();
message.To.Add(item);
message.Subject = "AutoInvoicing Notification";
message.From = new MailAddress("[email protected]");
message.Body = msgBody;
message.ReplyTo = new MailAddress("[email protected]");
message.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new SmtpClient("192.168.240.27");
smtp.Send(message);
message.Dispose();
}
catch (Exception e)
{
}
}
}
示例6: 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;
}
}
示例7: sendemail
public Boolean sendemail(String strFrom, string strTo, string strSubject, string strBody, string strAttachmentPath, bool IsBodyHTML)
{
Array arrToArray;
char[] splitter = { ';' };
arrToArray = strTo.Split(splitter);
MailMessage mm = new MailMessage();
mm.From = new MailAddress(strFrom);
mm.Subject = strSubject;
mm.Body = strBody;
mm.IsBodyHtml = IsBodyHTML;
mm.ReplyTo = new MailAddress("[email protected]");
foreach (string s in arrToArray)
{
mm.To.Add(new MailAddress(s));
}
if (strAttachmentPath != "")
{
try
{
//Add Attachment
Attachment attachFile = new Attachment(strAttachmentPath);
mm.Attachments.Add(attachFile);
}
catch { }
}
SmtpClient smtp = new SmtpClient();
try
{
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true; //Depending on server SSL Settings true/false
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "[email protected]";
NetworkCred.Password = "Timesofindia1";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;//Specify your port No;
smtp.Send(mm);
return true;
}
catch
{
mm.Dispose();
smtp = null;
return false;
}
}
示例8: enviaCorreo
public void enviaCorreo(string idPais, string usr, string pwd, string correoGZ, string archivo)
{
string rutaArchivo = (@"C:\Bcaribe\" + archivo + ".pdf");
string smtpServer = "smtp.gmail.com";
MailMessage correo = new MailMessage();
correo.From = new MailAddress("[email protected]");
correo.To.Add(correoGZ);
DataTable dtTaccion = tipoAccion(idPais);
for (int i = 0; i < dtTaccion.Rows.Count; i++)
{
correo.Bcc.Add(dtTaccion.Rows[i][0].ToString());
}
// correo.Bcc.Add(); // enviar mensajes ocultos
correo.Subject = "PDF-NUEVAS";
correo.Body = "FYI";
Attachment attachment = new Attachment(rutaArchivo); //create the attachment
correo.Attachments.Add(attachment); //add the attachment
// correo.BodyEncoding =
correo.Priority = MailPriority.Normal;
SmtpClient smtp = new SmtpClient();
smtp.Host = smtpServer;
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Timeout = 900000;
smtp.Credentials = new System.Net.NetworkCredential(usr, pwd);
try
{
smtp.Send(correo);
correo.Dispose();
if (File.Exists(rutaArchivo))
{
File.Delete(rutaArchivo);
}
//LabelError.Text = "Mensaje enviado satisfactoriamente";
}
catch (Exception ex)
{
// "error : "+ ex ;
EventLogger ev = new EventLogger();
ev.Save("ASP.NET 2.0.50727.0", ex);
//LabelError.Text = "ERROR: " + ex.Message;
}
}
示例9: SendFeedback
/// <summary>
/// Send player feedback to devs
/// </summary>
public void SendFeedback()
{
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
MailMessage message = new MailMessage();
message.From = new MailAddress(feedback_email);
message.To.Add(new MailAddress("[email protected]"));
message.Subject = string.Format("[{0}]-{1}", FeedbackTypeSelection.captionText.text, FeedbackSubjectInput.text);
message.Body = FeedbackInput.text;
client.SendAsync(message, "feedbacksent");
message.Dispose();
FeedbackSubjectInput.text = string.Empty;
FeedbackInput.text = string.Empty;
}
示例10: EnviarEmail
public static void EnviarEmail(string nombre, string email, string telefono, string mensaje)
{
MailMessage mailMessage = new MailMessage();
SmtpClient client = new SmtpClient();
try
{
mailMessage.To.Add(new MailAddress(ConfigurationManager.AppSettings[WebMobilConstant.EMAILCLIENT]));
mailMessage.Subject = "Se han enviado los siguientes datos de contacto de la pagina Inmobiliaria Irving Mobil";
mailMessage.Body = String.Format(@"Se han enviado los siguiente datos de la pagina de Inmobiliaria Irving Mobil<br>Nombre: {0}<br>Telefono: {1}<br>Mensaje: {2}", nombre, telefono, mensaje);
mailMessage.IsBodyHtml = true;
client.Send(mailMessage);
}
finally
{
mailMessage.Dispose();
client.Dispose();
}
}
示例11: ibRecover_Click
protected void ibRecover_Click(object sender, ImageClickEventArgs e)
{
// check id
Service ws = new Service();
Response result;
result = ws.MatchesUserIdAndEmailAddress(txtUser.Text.Trim(), txtEmail.Text.Trim());
if (!result.isSuccess)
{
lblMess.Text = result.errorMessage;
return;
}
if (result.dataValues == null || result.dataValues.Tables.Count == 0 || result.dataValues.Tables[0].Rows.Count == 0)
{
lblMess.Text = "Wrong User Id or Email";
return;
}
DataRow r = result.dataValues.Tables[0].Rows[0];
string pwd = r["password"].ToString();
// send password
SmtpClient client = new SmtpClient();
string body = "Your password is: <br>" + pwd;
string subj = "Your password";
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(txtEmail.Text.Trim()));
msg.Subject = subj;
msg.Body = body;
msg.IsBodyHtml = true;
try
{
client.Send(msg);
lblMess.Text = "Password sent.";
}
catch (Exception ex)
{
lblMess.Text = ex.ToString();
}
finally
{
msg.Dispose();
}
}
示例12: send
public static void send(string[] receivers, string title, string message)
{
SmtpClient smtp = new SmtpClient();
foreach (string receiver in receivers)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]", "Je.net Corporate Interface");
msg.To.Add(receiver);
//msg.Bcc.Add(receiver);
msg.Subject = title;
//msg.Body = "\n\n";
msg.Body += message;
msg.Body += "\n\n";
msg.Body += "-- The Je.net CI Team\n";
msg.IsBodyHtml = false;
smtp.Send(msg);
msg.Dispose();
}
}
示例13: SendMessage
/// <summary>
/// Transmit an email using HTML, returns true if email sent successfully
/// </summary>
/// <param name="to">string: To Address</param>
/// <param name="from">string: From Address</param>
/// <param name="fromName">string: From Display Name</param>
/// <param name="subject">string: Subject Line</param>
/// <param name="body">StringBuilder: Message Body in HTML or Text</param>
/// <param name="IsHtml">Bool: Is Email Message HTML</param>
public bool SendMessage(string to, string from, string fromName, string subject, StringBuilder body, bool IsHtml)
{
try
{
MailMessage message = new MailMessage(from, to, subject, body.ToString());
message.IsBodyHtml = IsHtml;
SmtpClient client = new SmtpClient(host, port);
client.UseDefaultCredentials = false;
client.Credentials = credentials;
client.Send(message);
message.Dispose();
return true;
}
catch
{
return false;
}
}
示例14: chapsubmit_Click
protected void chapsubmit_Click(object sender, ImageClickEventArgs e)
{
string mid = ConfigurationManager.AppSettings["mailid"], mpwd = ConfigurationManager.AppSettings["mailpwd"];
MailMessage mail = new MailMessage();
//this is used to retrieve the from address in webconfig file in appsettings
// mail.From=new System.Net.Mail.MailAddress(ConfigurationManager.AppSettings["fromaddress"]);
mail.From = new MailAddress(chapemail.Text,maildispname+" - SSN Alumni");
mail.ReplyToList.Add(new MailAddress(chapemail.Text));
mail.To.Add("[email protected]");
// mail subject
mail.Subject = "Request for Starting New Chapter";
// mail body
if (chapmsg.Value != "")
{
mail.Body = "Respected Sir/Madam," + "<br/>" + "<p style='padding-left:120px;'>We want to create a new chapter named '" + chapname.Text + " Chapter' at location " + chaploc.Text + ".We belong to the batch "+chapbatch.SelectedItem.Value+".</p><p>"+chapmsg.Value+"</p><p>The contact details are as follows:-<br/><br/>Email-Id : "+chapemail.Text+"<br/><br/>Contact Number :"+chapnum.Text+"</p> ";
}
else
{ mail.Body = ""; }
// mail.IsBodyHtml = true;
if (!Page.IsPostBack)
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential(mid, mpwd);
smtp.EnableSsl = true;
smtp.Send(mail);
}
Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", "DoSomething('Request for starting a new chapter has been sent successfully. You may receive a mail or call from alumni offcier for verification and enquiries. Thank you !!!');</script>", true);
clearboxes();
mail.Dispose();
}
示例15: SendEmail
public static void SendEmail(string fromUser,List<string> EmailTolist,string bodyMessage)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
//client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("", "");
MailAddress from = new MailAddress("[email protected]");
MailMessage message = new MailMessage();
message.From = from;
foreach (string email in EmailTolist)
{
message.To.Add(new MailAddress(email));
}
message.Body = "Date: " + DateTime.Now.ToShortDateString() + "<br />" + "<br />"; ;
message.Body += bodyMessage;
message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1";
message.SubjectEncoding = System.Text.Encoding.UTF8;
client.Send(message);
message.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}