本文整理汇总了C#中System.Web.Mail.MailMessage类的典型用法代码示例。如果您正苦于以下问题:C# MailMessage类的具体用法?C# MailMessage怎么用?C# MailMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MailMessage类属于System.Web.Mail命名空间,在下文中一共展示了MailMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendEmail
private static void SendEmail( string filePath )
{
Console.Write( "Crash: Sending email..." );
try
{
MailMessage message = new MailMessage();
message.Subject = "Automated RunUO Crash Report";
message.From = "RunUO";
message.To = Emails;
message.Body = "Automated RunUO Crash Report. See attachment for details.";
message.Attachments.Add( new MailAttachment( filePath ) );
SmtpMail.SmtpServer = EmailServer;
SmtpMail.Send( message );
Console.WriteLine( "done" );
}
catch
{
Console.WriteLine( "failed" );
}
}
示例2: SendMail
/// <summary>
/// Generic function to send mail
/// </summary>
/// <param name="smtpServer">SMTP Server Name/IP</param>
/// <param name="from">From Email Address</param>
/// <param name="to">To Email Address</param>
/// <param name="subject">Subject</param>
/// <param name="body">Body</param>
/// <returns>bool</returns>
public bool SendMail(string strSmtpServer, string strFrom, string strTo, string strSubject, string strBody)
{
MailMessage mailMsg = null;
Boolean blnMailSent = false;
try
{
mailMsg = new MailMessage();
mailMsg.From = strFrom;
mailMsg.To = strTo;
mailMsg.Cc = strFrom;
mailMsg.Subject = strSubject;
mailMsg.BodyFormat = MailFormat.Html;
mailMsg.Body = strBody;
if (strSmtpServer.Trim().Length != 0)
{
SmtpMail.SmtpServer = strSmtpServer;
}
SmtpMail.Send(mailMsg);
blnMailSent = true;
}
catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, Global .EXCEPTION_POLICY);
if (rethrow)
throw;
}
return blnMailSent;
}
示例3: btnForgotpass_Click
private void btnForgotpass_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if (Page.IsValid)
{
if (this.emailNotification)
{
BLUser wUser = new BLUser();
wUser.EMail = txtEMail.Text.Trim().ToLower();
wUser.Retrieve();
if (wUser.ID>0 && wUser.Enabled)
{
StringWriter writer = new StringWriter();
Server.Execute("email/emailForgotPass.aspx?email="+wUser.EMail, writer);
string strhtmlbody = writer.ToString();
// Response.Write(strhtmlbody);
// Response.End();
MailMessage objMailMessage = new MailMessage();
objMailMessage.Subject = siteName+": your password";
objMailMessage.From = this.emailNotificationCustomerFrom;
objMailMessage.To = wUser.EMail;
objMailMessage.Cc = this.emailNotificationCustomerCc;
objMailMessage.Bcc = this.emailNotificationCustomerBcc;
objMailMessage.Body = strhtmlbody;
objMailMessage.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = this.smtpServer;
SmtpMail.Send( objMailMessage );
}
}
Response.Redirect(".?page=login");
}
}
示例4: SendMail
public static void SendMail(string to, string bbc, string subject, string messages, string smtp, string port, string from, string user, string password)
{
try
{
System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
mail.To = to;
mail.Bcc = bbc;
mail.From = from;
mail.Subject = subject;
mail.BodyEncoding = Encoding.GetEncoding("utf-8");
mail.BodyFormat = MailFormat.Html;
mail.Body = messages;
mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = smtp;
mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = port;
mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = 1; // "true";
//mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"] = 60;
mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = user;
mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = password;
//SmtpMail.SmtpServer = smtp;
SmtpMail.Send(mail);
}
catch (Exception ex)
{
throw;
}
}
示例5: EmailBodyGeneral
public void EmailBodyGeneral(string toEmail, string subject, string txt)
{
try
{
MailMessage objMail = new MailMessage();
objMail.From = "EHR <[email protected]>";
objMail.To = toEmail;
objMail.Subject = subject;
objMail.BodyFormat = MailFormat.Html;
objMail.Body = txt;
SmtpMail.SmtpServer = "wczmail.wistron.com";
SmtpMail.Send(objMail);
}
catch (Exception e)
{
MailMessage objMail = new MailMessage();
objMail.From = "EHR <[email protected]>";
objMail.To = "EHR <[email protected]>";
objMail.Subject = subject;
objMail.BodyFormat = MailFormat.Html;
objMail.Body = "Email not deliver. <br />Did not deliver to: " + toEmail + e.Message;
SmtpMail.SmtpServer = "wczmail.wistron.com";
SmtpMail.Send(objMail);
}
}
示例6: SenddMail
/// <summary>
/// �����ʼ�
/// </summary>
/// <Author>Terminate</Author>
/// <CreateTime>2006-10-1</CreateTime>
/// <param name="MailFrom">������[�����˵�ַ]</param>
/// <param name="MailTo">�����˵�ַ</param>
/// <param name="MailSubject">�ż�����</param>
/// <param name="MailBody">�ż�����</param>
public static void SenddMail(string MailFrom,string MailTo,string MailSubject,string MailBody)
{
string SmtpServer,UserName,UserPwd;
bool MailCheck;
SmtpServer="mail.hbu.cn";
UserName="haodongliang";
UserPwd="[email protected]";
MailCheck=true;
MailMessage MailObj=new MailMessage();
SmtpMail.SmtpServer=SmtpServer;
if(MailCheck)
{
//��֤
MailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");//��֤��ʽ1��֤��0����֤
//�û���
MailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",UserName);
//����
MailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",UserPwd);
}
MailObj.From =MailFrom; //������
MailObj.To =MailTo; //�ռ���
MailObj.Subject =MailSubject; //�ʼ�����
MailObj.Priority =MailPriority.High; //�ʼ��ȼ�
MailObj.BodyFormat =MailFormat.Html; //�ʼ����ݸ�ʽ
MailObj.Body =MailBody; //�ʼ�����
SmtpMail.Send(MailObj);
}
示例7: Send
/// <summary>Envia um mail</summary>
public static bool Send( MailMessage message )
{
try {
if( message.From == null || message.From == "" ) {
message.From = Mailer.From;
}
#if DEBUG_MAIL
Log.log("----- SEND MAIL DEBUG ----------");
Log.log("To: {0}", message.To);
Log.log("From: {0}", message.From);
Log.log("Bcc: {0}", message.Bcc);
Log.log("Title: {0}", message.Subject);
Log.log("Message: {0}", message.Body);
Log.log("-------------------------------");
#endif
Log.log("Sending mail message '{0}'...", message.Subject );
SmtpMail.Send(message);
Log.log("... Done!");
return true;
} catch(System.Exception e) {
ExceptionLog.log(e, false);
return false;
}
}
示例8: SendMailMessage
/// <summary>
/// �����ʼ�
/// </summary>
/// <param name="to"></param>
/// <param name="from"></param>
/// <param name="subject"></param>
/// <param name="message"></param>
/// <param name="isAsync"></param>
private void SendMailMessage(string to, string from, string subject, string message, bool isAsync)
{
if (string.IsNullOrWhiteSpace(to))
throw new ArgumentNullException("to");
if (string.IsNullOrWhiteSpace(from))
throw new ArgumentNullException("from");
if (string.IsNullOrWhiteSpace(subject))
throw new ArgumentNullException("subject");
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = from;
mailMessage.To = to;
mailMessage.Subject = subject;
mailMessage.Body = message;
mailMessage.BodyFormat = MailFormat.Html;
mailMessage.BodyEncoding = System.Text.Encoding.UTF8; //�ʼ����ݱ���
SmtpMail.SmtpServer = this.SmtpServer; // �����ʼ��������˿�
//��֤
mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //�Ƿ���Ҫ��֤��һ����Ҫ��
mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.UserName); //�Լ�������û���
mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.Password); //�Լ����������
SmtpMail.Send(mailMessage);
}
catch (Exception ex)
{
throw new Exception("�����ʼ�����", ex);
}
}
示例9: button1_Click
private void button1_Click(object sender, System.EventArgs e)
{
if (boxFrom.Text == defaultFrom || boxFrom.Text.Split('@').Length != 2)
{
MessageBox.Show("Please enter your email address.");
return;
}
Hide();
MailMessage msg = new MailMessage();
msg.From = boxFrom.Text;
msg.To = boxEmailTo.Text;
msg.Subject = "NoxMapEditor Crash Report";
msg.Body = boxMessage.Text + (boxNotes.Text == "" ? "" : "\n\nNotes:\n" + boxNotes.Text);
bool sent = false;
foreach (string server in DnsLib.DnsApi.GetMXRecords(boxEmailTo.Text.Split('@')[1]))
{
SmtpMail.SmtpServer = server;
try
{
SmtpMail.Send(msg);
sent = true;
break;
}
catch (Exception) {}
}
if (!sent)
MessageBox.Show("Couldn't send mail message.");
}
示例10: btnSubmit_Click
protected void btnSubmit_Click(object sender, EventArgs e)
{
if ((tbxPhone.Text == "") && (tbxEmail.Text == ""))
{
CustomValidator1.IsValid = false;
}
else
{
SmtpMail.SmtpServer = "relay-hosting.secureserver.net";
MailMessage mm;
mm = new MailMessage();
mm.BodyFormat = MailFormat.Html;
mm.To = "[email protected]";
mm.From = "[email protected]";
mm.Subject = "New message generated from 1PromotionalProducts.com";
mm.Body = "*** THIS IS AN AUTOMATED EMAIL. DO NOT REPLY. ***<br /><br />";
mm.Body += "Name: " + tbxName.Text;
if (tbxEmail.Text != "")
{
mm.Body += "<br /><br />Reply Email: " + tbxEmail.Text;
}
if (tbxPhone.Text != "")
{
mm.Body += "<br /><br />Phone Number: " + tbxPhone.Text;
}
mm.Body += "<br /><br />Comment/Question:<br />" + tbxBody.Text.Replace("\r", "<br />").Replace("\n", "");
SmtpMail.Send(mm);
Response.Redirect("Default.aspx", true);
}
}
示例11: Send
public static String Send(StringBuilder strbBodyParam, String strSubjectParam,
String strEmailAddrParam)
{
String strCurrentStatus = "";
// prepare message with the report
MailMessage mmEmailMsg = new MailMessage();
mmEmailMsg.Body = strbBodyParam.ToString();
mmEmailMsg.From = SenderEmailAddr;
mmEmailMsg.Subject = strSubjectParam;
mmEmailMsg.To = strEmailAddrParam;
// send email with the report
// DirectSMTP.SmtpServer = "10.10.10.30";
// DirectSMTP.SmtpServer = "smtpgtwy.emcare.com";
// Changed SMTP server - 6/21/07, grf
//
DirectSMTP.SmtpServer = SmtpServerAddr;
String strResponse = DirectSMTP.Send(mmEmailMsg);
if (!strResponse.Equals(""))
{
strCurrentStatus = String.Format(
"ERROR: Could not send email to {0} through {1}\r\n\r\n{2}.",
strEmailAddrParam, DirectSMTP.SmtpServer, strResponse);
}
else
{
strCurrentStatus = String.Format("Sent report to email {0}", strEmailAddrParam);
}
return strCurrentStatus;
}
示例12: Sendmail
public static void Sendmail(string emailTo, string subject, string body)
{
try
{
string smtpAddress = "smtp.fairygroup.co.th";
int portNumber = 25;
bool enableSSL = true;
string emailFrom = "[email protected]";
string password = "[email protected]";
//string emailTo = conf.ConfigValue;
MailMessage Message = new MailMessage();
Message.To = password;
Message.From = emailFrom;
Message.Subject = subject;
Message.Body = body;
SmtpMail.SmtpServer = "smtp.fairygroup.co.th";
SmtpMail.Send(Message);
}
catch (System.Web.HttpException ehttp)
{
throw ehttp;
//Console.WriteLine("{0}", ehttp.Message);
//Console.WriteLine("Here is the full error message output");
//Console.Write("{0}", ehttp.ToString());
}
}
示例13: SendExceptionMail
public static void SendExceptionMail(string strMessage, string strSource, string strStackTrace)
{
try
{
string strFromMailId = ConfigurationManager.AppSettings.Get("EmailFrom");
string strMailServer = ConfigurationManager.AppSettings.Get("SmtpClient");
string strMailUser = ConfigurationManager.AppSettings.Get("UID");
string strMailPwd = ConfigurationManager.AppSettings.Get("Pwd");
string vstrSubject = "CSWeb Integration - Exception";
string vstrBody = "<b>Message: </b>" + strMessage + "<br/><br/><b>Sourse: </b>" + strSource + "<br/><br/><b>StackTrace: </b>" + strStackTrace;
string strMails = ConfigurationManager.AppSettings.Get("ErrorEmailTo");
MailMessage objMessage = new MailMessage();
if (strMailServer != "")
{
SmtpMail.SmtpServer = strMailServer;
objMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
objMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = strMailUser;
objMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = strMailPwd;
}
objMessage.From = strFromMailId;
objMessage.To = strMails;
objMessage.Subject = vstrSubject;
objMessage.Body = vstrBody;
objMessage.BodyFormat = MailFormat.Html;
SmtpMail.Send(objMessage);
}
catch (Exception exc)
{
}
}
示例14: ButtonSubmit_Click
protected void ButtonSubmit_Click(object sender, System.EventArgs e)
{
Server.ScriptTimeout = 1000;
Response.Flush();
SmtpMail.SmtpServer = "localhost";
MailMessage mail = new MailMessage();
mail.To = this.TextBoxTo.Text;
mail.Cc = this.TextBoxCc.Text;
mail.Bcc = this.TextBoxBcc.Text;
mail.From = this.TextBoxFrom.Text;
mail.Subject = this.TextBoxSubject.Text;
mail.Body = this.TextBoxBody.Text;
try
{
SmtpMail.Send(mail);
Response.Write("<p><strong> The Mail has been sent to: </strong></p>");
Response.Write("• To: " + mail.To + "</br>");
Response.Write("• Cc: " + mail.Cc + "</br>");
Response.Write("• Bcc: " + mail.Bcc + "</br>");
}
catch(System.Exception ex)
{
Response.Write("<p><strong>An erros has occured: " + ex.Message + "</strong><p>");
}
Response.Flush();
}
示例15: SendMessage
internal virtual void SendMessage(MailMessage message)
{
lock (emailLock)
{
SmtpMail.SmtpServer = configurationData.SmtpServer;
SmtpMail.Send(message);
}
}