This little snippet of code is to send an e-mail message thru C# .net
using system.net.mail;
private void EmailLogs(string EmailAddRec, string passName, bool SkipMsgBox)
{
String message1 = "" + this.TextBox1.Text + "";
DateTime now = DateTime.Now.Date;
MailMessage message = new MailMessage(
FromEmail,
EmailAddRecipient,
MailSubject + " on " + now.ToString(),
message1);
message.Bcc.Add(new MailAddress(BCCEmail));
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient(serverNameorIP);
client.UseDefaultCredentials = true;
try
{
client.Send(message);
if (!SkipMsgBox)
{
MessageBox.Show(passName + " Alert has been sent",
"Alert: " + this.AppTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Information );
}
else
{
this.SystrayMenuContext.BalloonTipText = passName +
" Alert has been sent!";
this.SystrayMenuContext.Text = this.AppTitle + ": Alert";
this.SystrayMenuContext.ShowBalloonTip(0x1388);
}
}
catch (Exception exception1)
{
Exception exception = exception1;
if (!SkipMsgBox)
{
MessageBox.Show("There was some exception: " +
exception.Message,
"Exception: " + this.AppTitle,
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
else
{
this.SystrayMenuContext.BalloonTipText = "There was some exception: " + exception.Message;
this.SystrayMenuContext.Text = this.AppTitle +
": Error Sending";
this.SystrayMenuContext.ShowBalloonTip(0x1388);
}
}
}
No comments:
Post a Comment