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 :: dotnet ef migrations to folder 
Csharp :: how to save a c# dictionary 
Csharp :: unity nested list 
Csharp :: how to deactivate objects through scripts in unity 
Csharp :: C# How to write Hello World 
Csharp :: c# parse the date in DD/MMM/YYYY format 
Csharp :: tostring tmpro unity 
Csharp :: unity hide mesh 
Csharp :: c# read file current directory 
Csharp :: c# create dynamic object 
Csharp :: c# inline if 
Csharp :: linq distinct count 
Csharp :: wpf set color in code 
Csharp :: covert char[] to string C# 
Csharp :: C# delete folder with all contents 
Csharp :: unity topdown 
Csharp :: c# find process by name 
Csharp :: c# first item i list 
Csharp :: c# if statement one line 
Csharp :: if button is pressed unity 
Csharp :: unity c# debug.log 
Csharp :: c# combobox selected item 
Csharp :: xamarin forms open new page on button click 
Csharp :: sort array by parity 
Csharp :: how to use the mouse scroll wheel to move the camera in unity 
Csharp :: unity post processing ui 2d 
Csharp :: c# loop through list of objects 
Csharp :: parse datetime c# 
Csharp :: clear gridview data in c# 
Csharp :: coroutine start unity 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =