Sending Email direct from the application

Asked

Viewed 67 times

0

Good morning, I am developing an application in which I need to take a String Array and send by Email directly from the application, would anyone have any notion of how I can do this ? Thank you

1 answer

0

Hello, I can give you an example I have done in C#, just pass as parameter your string array.

public static void SendEmail(string email, string subject, string[] mensagem, String[] comCopia = null)
        {
            NetworkCredential("[email protected]", "password");
            var assunto = subject;
            var emailObj = email;

            var mensagemObj = mensagem;

            string from = new MailAddress("[email protected]", subject).ToString();
            SmtpClient client = new SmtpClient("111.111.111.111")
            {
                UseDefaultCredentials = true,
                Credentials = new NetworkCredential("[email protected]", "password"),
                Port = 587
            };
            //string Server_Name = "http://" + Request.ServerVariables["server_name"] == "localhost" ? Request.ServerVariables["HTTP_HOST"] : Request.ServerVariables["server_name"] + "/project";

            var html = string.Format("<p>Email: {0}</p>><p>Mensagem: {1}</p>",
                email, mensagem);
            var msg = new MailMessage(from, emailObj, assunto, mensagemObj) { IsBodyHtml = true };
            if (comCopia!=null)
            {
                for (int i = 0; i < comCopia.Length; i++)
                {
                    msg.CC.Add(comCopia[i]);
                }
            }


            client.Send(msg);

        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.