-1

I want to send a html email with smtp account My Smtp Information is like that :

SMTP Hostname
Default SMTP Login
password
port 587

And How can I modified this code to use It ?

public static RestResponse SendSimpleMessage(string result, string mail, string api, string domain, string domainmail ,string sujet)
    {

        RestClient client = new RestClient();
        client.BaseUrl = new Uri(Url);
        client.Authenticator = new HttpBasicAuthenticator("api", api);
        RestRequest request = new RestRequest();
        request.AddParameter("domain",
                             domain, ParameterType.UrlSegment);
        request.Resource = "{domain}/messages";
        request.AddParameter("from", domainmail);
        request.AddParameter("to", mail);
        request.AddParameter("subject", sujet);
        request.AddParameter("html", result);
        request.Method = Method.POST;
        return (RestResponse)client.Execute(request);
    }
I.R
  • 51
  • 1
  • 1
  • 5

1 Answers1

0

There is a standard SmtpClient in C#.

var client = new SmtpClient(host, port);
client.EnableSsl = ssl;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(email, password);

var message = new MailMessage();
message.From = new MailAddress(fromAddress);
message.To.Add(toAddress);
message.Subject = subject;
var contentType = new ContentType("text/html");
var alternateView = AlternateView.CreateAlternateViewFromString(content, contentType);
message.AlternateViews.Add(alternateView);

client.Send(message);
Tommy
  • 3,044
  • 1
  • 14
  • 13
  • How can I add host and port ? help ! – I.R Jun 27 '16 at 15:32
  • `host` and `port` are given from your e-mail server. I know that **G-Mail** and **Outlook** (live, hotmail, outlook, msn) have information about this in mail settings. Try looking through settings as if you were trying to setup IMAP e-mail configuration. – Sometowngeek Jul 06 '16 at 03:18