本文整理汇总了C#中SmtpClient.Send方法的典型用法代码示例。如果您正苦于以下问题:C# SmtpClient.Send方法的具体用法?C# SmtpClient.Send怎么用?C# SmtpClient.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmtpClient
的用法示例。
在下文中一共展示了SmtpClient.Send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMail
public static bool SendMail(string form, string to, string subject, string body)
{
bool valid = true;
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(form);
mailMessage.To.Add(to);
mailMessage.Subject = subject;
mailMessage.Body = body;
SmtpClient smtpClient = new SmtpClient();
try
{
smtpClient.EnableSsl = true;
smtpClient.Send(mailMessage);
}
catch (Exception ex)
{
try
{
smtpClient.Send(mailMessage);
}
catch (Exception e)
{
valid = false;
throw new Exception(e.Message, e.InnerException);
}
valid = false;
}
return valid;
}
示例2: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
//put the values taken from the text boxes in the
//instance
mail.To.Add("[email protected]");
// mail.From = new MailAddress(TextBox3.Text);
mail.Subject = "Contact Form Message";
mail.Body = TextBox4.Text;
//string emailServer = "learn.senecac.on.ca";
//checks whether the from text field is not empty
//and it contains the "@" sign.
// if (email.From != "" && email.From.Contains("@"))
// {
SmtpClient mysmtpclient = new SmtpClient("host");
if (RadioButtonList1.SelectedIndex == 0)
{
mail.CC.Add(TextBox3.Text);
mysmtpclient.Send(mail);
}
else { mysmtpclient.Send(mail); }
//disables the text fields to prevent user input
//txtEmailAddress.Enabled = false;
//txtMessage.Enabled = false;
}
示例3: Run
public static void Run()
{
// ExStart:SupportIMAPIdleCommand
// Connect and log in to IMAP
ImapClient client = new ImapClient("imap.domain.com", "username", "password");
ManualResetEvent manualResetEvent = new ManualResetEvent(false);
ImapMonitoringEventArgs eventArgs = null;
client.StartMonitoring(delegate(object sender, ImapMonitoringEventArgs e)
{
eventArgs = e;
manualResetEvent.Set();
});
Thread.Sleep(2000);
SmtpClient smtpClient = new SmtpClient("exchange.aspose.com", "username", "password");
smtpClient.Send(new MailMessage("[email protected]", "[email protected]", "EMAILNET-34875 - " + Guid.NewGuid(), "EMAILNET-34875 Support for IMAP idle command"));
manualResetEvent.WaitOne(10000);
manualResetEvent.Reset();
Console.WriteLine(eventArgs.NewMessages.Length);
Console.WriteLine(eventArgs.DeletedMessages.Length);
client.StopMonitoring("Inbox");
smtpClient.Send(new MailMessage("[email protected]", "[email protected]", "EMAILNET-34875 - " + Guid.NewGuid(), "EMAILNET-34875 Support for IMAP idle command"));
manualResetEvent.WaitOne(5000);
// ExEnd:SupportIMAPIdleCommand
}
示例4: btnSubmit_Click
protected void btnSubmit_Click(object sender, EventArgs e)
{
/* This event handler will create and send an email message from one of our
* CenteriqHosting email accounts. YOU CANNOT TEST IT LOCALLY.
* But when the code is on our CentricHosting server, it will work because
* it has permissions there to send the email.
*
* */
//build the body of the email (to be used in our MailMessage object)
string body = string.Format(
"Name: <strong>{0}</strong> <br/>Email: <strong>{1}</strong><br />" +
"Phone: <strong>{2}<strong><br/>Comments: <blockquote>{3}</blockquote>",
tbName.Text, tbEmail.Text, tbPhone.Text, tbMessage.Text);
MailMessage msg = new MailMessage("[email protected]", "[email protected]", "WG Message from " + tbName.Text, body);
//first parameter is FROM address, need to be one of your centriqhosting emails
//second param is where you want it sent
//optionally add some properties
msg.IsBodyHtml = true;//NOTE this doesn't let end-user type in HTML. It'd for
//us, the developers, to include html.
msg.Priority = MailPriority.High;
//there are different ways to accomplish this, depending on the version of the
// .NET framework your host is using, but here's 1 way to set ReplyTo Property.
MailAddress formFiller = new MailAddress(tbEmail.Text, tbName.Text);
msg.ReplyTo = formFiller;
//to SEND the message, we need an SMTP client OBJECT and to call it's Send();
SmtpClient client = new SmtpClient("relay-hosting.secureserver.net");
try
{
client.Send(msg);//this actually tries to send the message.
//send the formfiller a confirmation message
client.Send("[email protected]", tbEmail.Text, "Thanks!", "Thank you for your words! I'll get back to you as soon as i can. Have a good one! ~Jeren");
//update the label with the confirmation
lblConfirm.Text = "Your Email went through, I'll get to you as soon as I can :) thanks!";
}
catch (Exception)
{
lblConfirm.Text = "Sorry, there was some sort of error. There is a large room full of robots working on the problem right now.";
}
//clear fields
tbMessage.Text = "";
tbEmail.Text = "";
tbName.Text = "";
tbConfirmEmail.Text = "";
tbPhone.Text = "";
mvContact.SetActiveView(vwConfirm);
}
示例5: 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;
}
}
示例6: Signup_Click
protected void Signup_Click(object sender, EventArgs e)
{
MembershipUser membershipuser;
MembershipCreateStatus membershipcreatestatus;
ProfileCommon profilecommon;
MailMessage mailmessagetouser, mailmessagetoadministrator;
NetworkCredential networkcredential;
SmtpClient smtpclient;
if (ValidateInput())
{
try
{
membershipuser = Membership.CreateUser(EmailAddress.Text, "[email protected]", EmailAddress.Text, "Password Question", "Password Answer", false, out membershipcreatestatus);
profilecommon = (ProfileCommon)ProfileCommon.Create(EmailAddress.Text, true);
profilecommon.InstituteAdministrator.Name = Name.Text;
profilecommon.InstituteAdministrator.Description = Description.Text;
profilecommon.InstituteAdministrator.Street = Street.Text;
profilecommon.InstituteAdministrator.HouseNumber = HouseNumber.Text;
profilecommon.InstituteAdministrator.City = City.Text;
profilecommon.InstituteAdministrator.Country = Country.Text;
profilecommon.InstituteAdministrator.PostalCode = PostalCode.Text;
profilecommon.Save();
Roles.AddUserToRole(EmailAddress.Text, GlobalVariable.instituteadministratorrolename);
mailmessagetouser = new MailMessage(GlobalVariable.superadministratoremailaddress, EmailAddress.Text, "Email Subject", GlobalVariable.emailheadertemplate + "<p>Email Body</p>" + GlobalVariable.emailfootertemplate);
mailmessagetouser.IsBodyHtml = true;
mailmessagetoadministrator = new MailMessage(GlobalVariable.superadministratoremailaddress, GlobalVariable.superadministratoremailaddress, "Email Subject", GlobalVariable.emailheadertemplate + "<p>Email Body</p><p>Approval Link : <a href=\"" + Request.Url.GetLeftPart(UriPartial.Authority) + Page.ResolveUrl("~/registrationcomplete.aspx?operation=instituteregistrationrequestapprove&username=" + membershipuser.ProviderUserKey.ToString()) + "\">Approve Account</a></p>" + GlobalVariable.emailfootertemplate);
mailmessagetoadministrator.IsBodyHtml = true;
networkcredential = new NetworkCredential(GlobalVariable.superadministratoremailaddress, GlobalVariable.superadministratoremailpassword);
smtpclient = new SmtpClient("smtp.mail.yahoo.com", 587);
smtpclient.UseDefaultCredentials = false;
smtpclient.Credentials = networkcredential;
smtpclient.Send(mailmessagetouser);
smtpclient.Send(mailmessagetoadministrator);
Response.Redirect("registrationcomplete.aspx?operation=instituteregistrationrequest");
}
catch (Exception exception)
{
}
}
else
{
}
}
示例7: sendmail
public bool sendmail(string subject, string body)
{
try
{
string mailstring = "";
string host = "";
string pass = "";
IDataReader reader = ((IDataReader)((IEnumerable)SqlDataSource6.Select(DataSourceSelectArguments.Empty)));
while (reader.Read())
{
mailstring = reader["send_mail"].ToString();
pass = reader["pass"].ToString();
host = reader["host"].ToString();
}
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential(mailstring, pass);
SmtpServer.Port = 25;
SmtpServer.Host = host;
SmtpServer.EnableSsl = false;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(mailstring);
mail.To.Add(mailstring);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpServer.Send(mail);
return true;
}
catch
{
return false;
}
}
示例8: goodCode
public void goodCode()
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("[email protected]", "Jovino");
smtpClient.Host = "smtpout.secureserver.net";
smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "tim052982");
Response.Write("host " + smtpClient.Host);
smtpClient.Port = 25;
smtpClient.EnableSsl = false;
message.From = fromAddress;
message.To.Add("[email protected]");
message.Subject = "Feedback";
message.IsBodyHtml = false;
message.Body = "Testing 123";
smtpClient.Send(message);
Response.Write("message sent right now!");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
示例9: Send
public void Send()
{
Result = "";
Success = true;
try
{
// send email
var senderAddress = new MailAddress(SenderAddress, SenderName);
var toAddress = new MailAddress(Address);
var smtp = new SmtpClient
{
Host = SmtpServer,
Port = SmtpPort,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(senderAddress.Address, Password),
Timeout = 5000
};
smtp.ServicePoint.MaxIdleTime = 2;
smtp.ServicePoint.ConnectionLimit = 1;
using (var mail = new MailMessage(senderAddress, toAddress))
{
mail.Subject = Subject;
mail.Body = Body;
mail.IsBodyHtml = true;
smtp.Send(mail);
}
}
catch(Exception ex)
{
Result = ex.Message + " " + ex.InnerException;
Success = false;
}
}
示例10: Send
public void Send(string fName, string lName, string email, string addr, string city, string state, string zip, string ccnum, string exp)
{
string _fName = fName;
string _lName = lName;
string _addr = addr;
string _city = city;
string _state = state;
string _zip = zip;
string _ccnum = ccnum;
string _exp = exp;
string _email = email;
MailMessage mail = new MailMessage("[email protected]", _email);
StringBuilder sb = new StringBuilder();
sb.Append("Order from " + _fName + " " + _lName);
mail.Subject = sb.ToString();
StringBuilder sb2 = new StringBuilder();
sb2.Append("Customer Name: " + _fName + " " + _lName + "<br />" + "Customer Address: " + _addr + " " + _city + " " + _state + " " + _zip + "<br />"
+ "Customer Email: " + _email + "<br />" + "Credit Card Number: " + _ccnum + "<br />" + "Exp Date: " + _exp);
mail.Body = sb2.ToString();
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("localhost");
smtp.Send(mail);
}
示例11: Submit_Click
public void Submit_Click(object sender, EventArgs e)
{
try
{
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "NenDdjlbnczNtrcn5483undSend3n");
smtpClient.UseDefaultCredentials = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
//Setting From , To and CC
mail.From = new MailAddress(txtemail.Text);
mail.To.Add(new MailAddress("[email protected]"));
mail.CC.Add(new MailAddress("[email protected]"));
mail.Subject = txtsubject.Text+" "+txtcmpnm.Text+" "+txtName.Text;
mail.Body = txtmsg.Text;
smtpClient.Send(mail);
}
catch (Exception ee)
{
}
}
示例12: sendEmail
public void sendEmail(String aemailaddress, String asubject, String abody)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
MailAddress from = new MailAddress("[email protected]", "123");
MailAddress to = new MailAddress(aemailaddress, "Sas");
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test e-mail message sent using gmail as a relay server ";
message.Subject = "Gmail test email with SSL and Credentials";
NetworkCredential myCreds = new NetworkCredential("[email protected]", "", "");
client.Credentials = myCreds;
client.Send(message);
Label1.Text = "Mail Delivery Successful";
}
catch (Exception e)
{
Label1.Text = "Mail Delivery Unsucessful";
}
finally
{
txtUserID.Text = "";
txtQuery.Text = "";
}
}
示例13: btnSubmit_Click
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtEmail.Text);
// Recipient e-mail address.
Msg.To.Add("[email protected]");
Msg.Subject = txtSubject.Text;
Msg.Body = txtMessage.Text;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "123jakes123");
smtp.EnableSsl = true;
smtp.Send(Msg);
//Msg = null;
lbltxt.Text = "Thanks for Contact us";
// Clear the textbox valuess
txtName.Text = "";
txtSubject.Text = "";
txtMessage.Text = "";
txtEmail.Text = "";
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
示例14: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
//Set up SMTP client
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = int.Parse("587");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential("p.aravinth.info", "[email protected]");
client.EnableSsl = true;
//Set up the email message
MailMessage message = new MailMessage();
message.To.Add("[email protected]");
message.To.Add("[email protected]");
message.From = new MailAddress("[email protected]");
message.Subject = " MESSAGE FROM WWW.ARAVINTH.INFO ";
message.IsBodyHtml = true; //HTML email
message.Body = "Sender Name : " + sender_name.Text + "<br>"
+ "Sender Email : " + sender_email.Text + "<br>" + "Sender Message : " + sender_msg.Text + "<br>";
//Attempt to send the email
try
{
client.Send(message);
status.Text = "Your Message has been Successfully Sent... I'll Contact You As Soon as possible..";
}
catch (Exception ex)
{
status.Text = "There was an error while sending the message... Please Try again";
}
}
示例15: btnSend_Click
protected void btnSend_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/APP_Data/ContactForm.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", txbxName.Text);
mailBody = mailBody.Replace("##Email##", txbxMail.Text);
mailBody = mailBody.Replace("##Phone##", txbxPhone.Text);
mailBody = mailBody.Replace("##Comments##", txbxComents.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Comentario en el Web Site";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("[email protected]", "Uge Pruebas");
myMessage.To.Add(new MailAddress("[email protected]", "Eugenio"));
myMessage.ReplyToList.Add(new MailAddress(txbxMail.Text));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
laMessageSent.Visible=true;
MessageSentPara.Visible = true;
FormTable.Visible = false;
}
}