本文整理汇总了C#中SmtpClient类的典型用法代码示例。如果您正苦于以下问题:C# SmtpClient类的具体用法?C# SmtpClient怎么用?C# SmtpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SmtpClient类属于命名空间,在下文中一共展示了SmtpClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: godaddyMail
public void godaddyMail()
{
//http://stackoverflow.com/questions/2032860/send-smtp-email-through-godaddy
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]");
mail.Subject = "HelpDesk Response";
mail.Body = "Your HelpDesk response was recieved.";
mail.IsBodyHtml = true;
//Attachment attachment = new Attachment(fileName);
//mail.Attachments.Add(attachment); //add the attachment
SmtpClient client = new SmtpClient();
//client.Credentials = new System.Net.NetworkCredential("customdb", "Holy1112!");
client.Host = "relay-hosting.secureserver.net";
try
{
client.Send(mail);
}
catch (Exception ex)
{
//the exception
}
}
示例2: SendAsync
public Task SendAsync(IdentityMessage message)
{
if (ConfigurationManager.AppSettings["EmailServer"] != "{EmailServer}" &&
ConfigurationManager.AppSettings["EmailUser"] != "{EmailUser}" &&
ConfigurationManager.AppSettings["EmailPassword"] != "{EmailPassword}")
{
System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();
// To
mailMsg.To.Add(new MailAddress(message.Destination, ""));
// From
mailMsg.From = new MailAddress("[email protected]", "DurandalAuth administrator");
// Subject and multipart/alternative Body
mailMsg.Subject = message.Subject;
string html = message.Body;
mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));
// Init SmtpClient and send
SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["EmailServer"], Convert.ToInt32(587));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["EmailUser"], ConfigurationManager.AppSettings["EmailPassword"]);
smtpClient.Credentials = credentials;
return Task.Factory.StartNew(() => smtpClient.SendAsync(mailMsg, "token"));
}
else
{
return Task.FromResult(0);
}
}
示例3: sendmail
public void sendmail(string idinmueble, string mail, string emailAlternativo, string calles, string numero)
{
//Primero debemos importar los namespace
//El metodo que envia debe contener lo siguiente
MailMessage objEmail = new MailMessage();
objEmail.From = new MailAddress("[email protected]");
objEmail.ReplyTo = new MailAddress("[email protected]");
//Destinatario
objEmail.To.Add(mail);
//objEmail.To.Add(mail1);
if (emailAlternativo != "")
{
objEmail.CC.Add(emailAlternativo);
}
objEmail.Bcc.Add("[email protected]");
objEmail.Priority = MailPriority.Normal;
//objEmail.Subject = "hola";
objEmail.IsBodyHtml = true;
objEmail.Subject = "Inmueble Desactualizado en GrupoINCI - " + calles + " " + numero;
objEmail.Body = htmlMail(idinmueble);
SmtpClient objSmtp = new SmtpClient();
objSmtp.Host = "localhost ";
objSmtp.Send(objEmail);
}
示例4: 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";
}
}
示例5: 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());
}
}
示例6: 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;
}
}
示例7: SendMail
public static bool SendMail(string gMailAccount, string password, string to, string subject, string message)
{
try
{
NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(gMailAccount);
msg.To.Add(new MailAddress(to));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);
return true;
}
catch (Exception)
{
return false;
}
}
示例8: Send
public static bool Send(PESMail mail)
{
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new NetworkCredential(ConfigurationManager.AppSettings.Get("Sender"), ConfigurationManager.AppSettings.Get("MailPass"));
smtp.Host = ConfigurationManager.AppSettings.Get("SmtpHost");
smtp.Port = Commons.ConvertToInt(ConfigurationManager.AppSettings.Get("SmtpPort"),25);
smtp.EnableSsl = true;
using (MailMessage message = new MailMessage())
{
message.From = new MailAddress(ConfigurationManager.AppSettings.Get("defaultSender"));
for (int i = 0; i < mail.List.Count;i++ )
{
message.To.Add(mail.List[i].ToString());
}
message.Subject = mail.Subject;
message.Body = mail.Content;
message.IsBodyHtml = mail.IsHtml;
try
{
smtp.Send(message);
return true;
}
catch
{
return false;
}
}
}
示例9: 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 = "";
}
}
示例10: SendEmail
private void SendEmail()
{
String content = string.Empty;
var objEmail = new MailMessage();
objEmail.From = new MailAddress("[email protected]", "Sender");
objEmail.Subject = "Test send email on GoDaddy account";
objEmail.IsBodyHtml = true;
var smtp = new SmtpClient();
smtp.Host = "smtpout.secureserver.net";
smtp.Port = 80;
smtp.EnableSsl = false;
// and then send the mail
// ServicePointManager.ServerCertificateValidationCallback =
//delegate(object s, X509Certificate certificate,
//X509Chain chain, SslPolicyErrors sslPolicyErrors)
//{ return true; };
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "#passw0rd#");
objEmail.To.Add("[email protected]");
objEmail.To.Add("[email protected]");
objEmail.Body = content;
smtp.Send(objEmail);
}
示例11: Run
public static void Run()
{
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_SMTP();
string dstEmail = dataDir + "Message.eml";
// Create an instance of the MailMessage class
MailMessage message = new MailMessage();
// Import from EML format
message = MailMessage.Load(dstEmail, new EmlLoadOptions());
// Create an instance of SmtpClient class
SmtpClient client = new SmtpClient("smtp.gmail.com", 587, "[email protected]", "your.password");
client.SecurityOptions = SecurityOptions.Auto;
try
{
// Client.Send will send this message
client.Send(message);
Console.WriteLine("Message sent");
}
catch (Exception ex)
{
Trace.WriteLine(ex.ToString());
}
Console.WriteLine(Environment.NewLine + "Email sent using EML file successfully. " + dstEmail);
}
示例12: mail_axrequest
public static void mail_axrequest(string name, string from, string to, string cc, string designation, string company, string contact, string email, string message)
{
MailMessage mMailMessage = new MailMessage();
mMailMessage.From = new MailAddress(from);
mMailMessage.To.Add(new MailAddress(to));
if ((cc != null) && (cc != string.Empty))
{
mMailMessage.CC.Add(new MailAddress(cc));
//mMailMessage.CC.Add(new MailAddress(bcc));
}
mMailMessage.Subject = "One Comment from " + name;
mMailMessage.Body = message;
System.Text.StringBuilder builder = new System.Text.StringBuilder();
builder.AppendLine("<strong>" + "Name : " + "</strong>" + name + "<br />");
builder.AppendLine("<strong>" + "Designation : " + "</strong>" + designation + "<br />");
builder.AppendLine("<strong>" + "Company : " + "</strong>" + company + "<br />");
builder.AppendLine("<strong>" + "Contact : " + "</strong>" + contact + "<br />");
builder.AppendLine("<strong>" + "Email : " + "</strong>" + email + "<br />");
mMailMessage.Body = builder.ToString();
mMailMessage.IsBodyHtml = true;
mMailMessage.Priority = MailPriority.Normal;
SmtpClient server = new SmtpClient("pod51021.outlook.com");
server.Credentials = new System.Net.NetworkCredential("[email protected]", "[email protected]@123", "www.cembs.com");
server.Port = 587;
server.EnableSsl = true;
server.Send(mMailMessage);
}
示例13: Button1_Click
//protected void gridView_Load(object sender, EventArgs e)
//{
// for (int i = 0; i < GridView1.Rows.Count; i++)
// {
// if ((DateTime.Parse(GridView1.Rows[i].Cells[2].Text)) < (DateTime.Parse(DateTime.Today.ToShortDateString())))
// {
// GridView1.Rows[i].Visible = false;
// //GridView1.da
// }
// }
//}
protected void Button1_Click(object sender, EventArgs e)
{
MyService.UserWebService uws = new UserWebService();
uws.Credentials = System.Net.CredentialCache.DefaultCredentials;
int id = uws.getAppointmentID(Int32.Parse(DropDownList1.SelectedValue), DateTime.Parse(Label1.Text));
int status = 1;
uws.makeStudentAppointment(id, sid, txtSubject.Text, DateTime.Parse(DropDownList2.SelectedValue), DateTime.Parse(txtEndtime.Text), status);
// SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
//smtp.UseDefaultCredentials = false;
//smtp.Credentials = new NetworkCredential("[email protected]","were690vase804");
//smtp.EnableSsl = true;
//smtp.Send("[email protected]", "[email protected]", "Appointment", "Appointment Successfull");
MailAddress mailfrom = new MailAddress("[email protected]");
MailAddress mailto = new MailAddress("[email protected]");
MailMessage newmsg = new MailMessage(mailfrom, mailto);
newmsg.Subject = "APPOINTMENT";
newmsg.Body = "Appointment Successful";
// Attachment att = new Attachment("C:\\...file path");
// newmsg.Attachments.Add(att);
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("[email protected]","were690vase804");
smtp.EnableSsl = true;
smtp.Send(newmsg);
Response.Write(@"<script language='javascript'>alert('Appointment Made and Confirmation has been sent to your mail')</script>");
}
示例14: 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);
}
示例15: btnPasswordRecover_Click
protected void btnPasswordRecover_Click(object sender, EventArgs e)
{
using (eCommerceDBEntities context = new eCommerceDBEntities())
{
Customer cust = context.Customers.Where(i => i.email==txtEmail.Text).FirstOrDefault();
if (cust == null)
{
string title = "User ID not found";
string message = "No user found with the given email ID. Please provide the email ID you signed up with.";
string jsFunction = string.Format("showNotification('{0}','{1}')", title, message);
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "notify", jsFunction, true);
}
else
{
string email = cust.email;
string password = cust.Password;
MailMessage mail = new MailMessage("[email protected]", email);
mail.Subject = "Password for your eCommerce ID";
mail.Body = "Your password for eCommerce is : " + password;
mail.IsBodyHtml = false;
SmtpClient smp = new SmtpClient();
//smp.Send(mail);
string title = "Password sent!";
string message = "Your password has been sent to " + email;
string jsFunction = string.Format("showNotification('{0}','{1}')", title, message);
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "notify", jsFunction, true);
}
}
}