ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Demostracion de C#


Enviado por   •  1 de Octubre de 2015  •  Apuntes  •  875 Palabras (4 Páginas)  •  69 Visitas

Página 1 de 4

using System.Collections.Generic;

using System.Configuration;

using System.Net;

using System.Net.Configuration;

using System.Net.Mail;

using System.Web.Configuration;

namespace com.ooit.edu {

public class MailService {

private static MailService instance;

// get singleton

public static MailService GetInstance() {

return instance == null ? instance = new MailService() : instance;

}

// eg @"~\web.config"

public static string WEB_CONFIG_PATH { get; set; }

private MailService() { }

// send regular mail

public void SendMail(string from, IList<string> tos, string subject, string text,

string smtpHost, string userid, string passwd) {

// create message

MailMessage msg = new MailMessage();

msg.From = new MailAddress(from);

foreach (string to in tos) {

msg.To.Add(new MailAddress(to));

}

msg.Subject = subject;

msg.Body = text;

msg.IsBodyHtml = true;

msg.Priority = MailPriority.High;

// connect to smtp server

NetworkCredential SMTPUserInfo = new NetworkCredential(userid, passwd);

SmtpClient c = new SmtpClient(smtpHost);

c.Credentials = SMTPUserInfo;

// send

c.Send(msg);

}

// send mail within the context of ASP.NET

public void SendMailInASP(IList<string> tos, string subject, string text) {

// read configuration file usually : @"~\web.config"

Configuration config = WebConfigurationManager.OpenWebConfiguration(WEB_CONFIG_PATH);

MailSettingsSectionGroup settings =

(MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");

MailMessage msg = new MailMessage();

msg.From = new MailAddress(settings.Smtp.From);

...

Descargar como (para miembros actualizados) txt (3 Kb) pdf (44 Kb) docx (13 Kb)
Leer 3 páginas más »
Disponible sólo en Clubensayos.com