Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# send email

using System.Net;
using System.Net.Mail;
using System.Net.Mime;

...
try
{

   SmtpClient mySmtpClient = new SmtpClient("my.smtp.exampleserver.net");

    // set smtp-client with basicAuthentication
    mySmtpClient.UseDefaultCredentials = false;
   System.Net.NetworkCredential basicAuthenticationInfo = new
      System.Net.NetworkCredential("username", "password");
   mySmtpClient.Credentials = basicAuthenticationInfo;

   // add from,to mailaddresses
   MailAddress from = new MailAddress("test@example.com", "TestFromName");
   MailAddress to = new MailAddress("test2@example.com", "TestToName");
   MailMessage myMail = new System.Net.Mail.MailMessage(from, to);

   // add ReplyTo
   MailAddress replyTo = new MailAddress("reply@example.com");
   myMail.ReplyToList.Add(replyTo);

   // set subject and encoding
   myMail.Subject = "Test message";
   myMail.SubjectEncoding = System.Text.Encoding.UTF8;

   // set body-message and encoding
   myMail.Body = "<b>Test Mail</b><br>using <b>HTML</b>.";
   myMail.BodyEncoding = System.Text.Encoding.UTF8;
   // text or html
   myMail.IsBodyHtml = true;

   mySmtpClient.Send(myMail);
}

catch (SmtpException ex)
{
  throw new ApplicationException
    ("SmtpException has occured: " + ex.Message);
}
catch (Exception ex)
{
   throw ex;
}
Comment

c# send email


using System.Net;
using System.Net.Mail;
using System.Net.Mime;

...
try
{

   SmtpClient mySmtpClient = new SmtpClient("my.smtp.exampleserver.net");

    // set smtp-client with basicAuthentication
    mySmtpClient.UseDefaultCredentials = false;
   System.Net.NetworkCredential basicAuthenticationInfo = new
      System.Net.NetworkCredential("username", "password");
   mySmtpClient.Credentials = basicAuthenticationInfo;

   // add from,to mailaddresses
   MailAddress from = new MailAddress("test@example.com", "TestFromName");
   MailAddress to = new MailAddress("test2@example.com", "TestToName");
   MailMessage myMail = new System.Net.Mail.MailMessage(from, to);

   // add ReplyTo
   MailAddress replyTo = new MailAddress("reply@example.com");
   myMail.ReplyToList.Add(replyTo);

   // set subject and encoding
   myMail.Subject = "Test message";
   myMail.SubjectEncoding = System.Text.Encoding.UTF8;

   // set body-message and encoding
   myMail.Body = "<b>Test Mail</b><br>using <b>HTML</b>.";
   myMail.BodyEncoding = System.Text.Encoding.UTF8;
   // text or html
   myMail.IsBodyHtml = true;

   mySmtpClient.Send(myMail);
}

catch (SmtpException ex)
{
  throw new ApplicationException
    ("SmtpException has occured: " + ex.Message);
}
catch (Exception ex)
{
   throw ex;
}

Comment

send mail C#

var values = new Dictionary<string, string>
{
    { "thing1", "hello" },
    { "thing2", "world" }
};

var content = new FormUrlEncodedContent(values);

var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);

var responseString = await response.Content.ReadAsStringAsync();
Comment

c# how to send a email

// in the beginning of the file
using System.Net;
using System.Net.Mail;
MailAddress to = new MailAddress("charles@westminster.co.uk");
MailAddress from = new MailAddress("piotr@mailtrap.io");
MailMessage message = new MailMessage(from, to);
message.Subject = "Good morning, Charles";
message.Body = "Charles, Long time no talk. Would you be up for lunch in Soho on Monday? I'm paying.;";
SmtpClient client = new SmtpClient("smtp.server.address", 2525)
{
    Credentials = new NetworkCredential("smtp_username", "smtp_password"),
    EnableSsl = true
// specify whether your host accepts SSL connections
};
// code in brackets above needed if authentication required
try
{
  client.Send(message);
}
catch (SmtpException ex)
{
  Console.WriteLine(ex.ToString());
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: one line condition c# 
Csharp :: entity 
Csharp :: EF .NET4 INSERT IMPROVE PERFORMACE 
Csharp :: pork hub 
Csharp :: calculate string length vs pixels c# 
Csharp :: How to find column name with column index in DataGridView 
Csharp :: linq while loop in c# 
Csharp :: How to remove an element from Array List in C#? 
Csharp :: json serialize object capitalization config 
Csharp :: f sharp global variable 
Csharp :: unity android keycodes 
Csharp :: converting dens_rank and row_number to linq 
Csharp :: c# different getter setter types 
Csharp :: Unity Scene Load by BuildIndex 
Csharp :: c# entity mvc get user from razor layout 
Csharp :: nullable IList to List 
Csharp :: save and query mongodb collection as dynamic ExpandoObject 
Csharp :: data types of document in asp dot net frame work 
Csharp :: v bux free 
Csharp :: C# milisecond to h m s 
Csharp :: to string c# fields 
Csharp :: C# Search in JSON without deserialization 
Csharp :: epplus how to align text to right 
Csharp :: iqkeyboardmanagerswift 
Csharp :: unity how to change visual studio version 
Csharp :: c# regex double of some letters only 
Csharp :: c# easy 
Csharp :: Xamarin Forms iOS Picker done 
Csharp :: return a list of list from yaml via C# 
Csharp :: push vaiable in array c# 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =