Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Net.Mail;
- namespace TestEmail
- {
- class Program
- {
- static void Main(string[] args)
- {
- string username = "office@twinklestar.ro";
- string pass = "Ianuarie!123";
- string sentTo = "mirela.zavate@easymedical.ro";
- List<string> cc = new List<string>();
- List<string> attach = new List<string>();
- string subject = "test";
- string body = "test";
- string host = "bssd02.octosquid.com";//mail.twinklestar.ro" ;
- string port = "465";
- string fromDisplayName = "office@twinklestar.ro";
- string fromEmail = "office@twinklestar.ro";
- string enableSSL = "1";
- SendFullEmails(username, pass, sentTo, cc, attach, subject, body, host, port, fromDisplayName, fromEmail,
- enableSSL);
- }
- public static void SendFullEmails(string credentialUserName, string credentialPassword, string sentTo, List<string> sendCC,
- List<string> attachments, string subject, string body, string smtpHost, string smtpPort, string fromDisplayName,
- string fromEmailAddress, string enableSSL)
- {
- try
- {
- MailMessage msgMail = new MailMessage(new MailAddress(fromEmailAddress, fromDisplayName), new MailAddress(sentTo));
- msgMail.Subject = subject;
- msgMail.IsBodyHtml = true;
- msgMail.Body = body;
- foreach (string cc in sendCC)
- msgMail.CC.Add(new MailAddress(cc));
- foreach (string attach in attachments)
- msgMail.Attachments.Add(new Attachment(attach));
- SmtpClient client = new SmtpClient(smtpHost);
- client.Port = Convert.ToInt32(smtpPort);
- //client.UseDefaultCredentials = false;
- // client.DeliveryMethod = SmtpDeliveryMethod.Network;
- //client.Timeout = 600000;
- client.Credentials = new System.Net.NetworkCredential(credentialUserName, credentialPassword);
- //client.UseDefaultCredentials = true;
- if (enableSSL == "1")
- client.EnableSsl = true;
- else
- client.EnableSsl = false;
- client.Send(msgMail);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement