![]() Главная страница Случайная страница КАТЕГОРИИ: АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника |
MailSettings
Создадим одиночный конфиг для настроек по работе с smtp-почтой. Нам понадобятся: · SmtpServer. Имя сервера. · SmtpPort. Порт, обычно 25й. · SmtpUserName. Логин. · SmtpPassword. Пароль. · SmtpReply. Обратный адрес в строке Reply-to. · SmtpUser. Имя пользователя в строке From. · EnableSsl. Да/нет, использовать ли работу по Ssl. Файл (/Global/Config/MailSetting.cs): public class MailSetting: ConfigurationSection { [ConfigurationProperty(" SmtpServer", IsRequired = true)] public string SmtpServer { get { return this[" SmtpServer" ] as string; } set { this[" SmtpServer" ] = value; } }
[ConfigurationProperty(" SmtpPort", IsRequired = false, DefaultValue=" 25")] public int SmtpPort { get { return (int)this[" SmtpPort" ]; } set { this[" SmtpPort" ] = value; } }
[ConfigurationProperty(" SmtpUserName", IsRequired = true)] public string SmtpUserName { get { return this[" SmtpUserName" ] as string; } set { this[" SmtpUserName" ] = value; } }
[ConfigurationProperty(" SmtpPassword", IsRequired = true)] public string SmtpPassword { get { return this[" SmtpPassword" ] as string; } set { this[" SmtpPassword" ] = value; } }
[ConfigurationProperty(" SmtpReply", IsRequired = true)] public string SmtpReply { get { return this[" SmtpReply" ] as string; } set { this[" SmtpReply" ] = value; } }
[ConfigurationProperty(" SmtpUser", IsRequired = true)] public string SmtpUser { get { return this[" SmtpUser" ] as string; } set { this[" SmtpUser" ] = value; } }
[ConfigurationProperty(" EnableSsl", IsRequired = false, DefaultValue=" false")] public bool EnableSsl { get { return (bool)this[" EnableSsl" ]; } set { this[" EnableSsl" ] = value; } } } Добавим в Web.config: < section name=" mailConfig" type=" LessonProject.Global.Config.MailSetting, LessonProject" /> И < mailConfig SmtpServer=" smtp.gmail.com" SmtpPort=" 587" SmtpUserName=" lxndrpetrov" SmtpPassword=" **********" SmtpReply=" lxndrpetrov@gmail.com" SmtpUser=" test" EnableSsl=" true" /> Добавим все это теперь в IConfig.cs и Сonfig.cs (/Global/Config/IConfig.cs): public interface IConfig { string Lang { get; }
IQueryable< IconSize> IconSizes { get; }
IQueryable< MimeType> MimeTypes { get; }
MailSetting MailSetting { get; } }
И public IQueryable< IconSize> IconSizes { get { IconSizesConfigSection configInfo = (IconSizesConfigSection)ConfigurationManager.GetSection(" iconConfig"); return configInfo.IconSizes.OfType< IconSize> ().AsQueryable< IconSize> ();
} }
public IQueryable< MimeType> MimeTypes { get { MimeTypesConfigSection configInfo = (MimeTypesConfigSection)ConfigurationManager.GetSection(" mimeConfig"); return configInfo.MimeTypes.OfType< MimeType> ().AsQueryable< MimeType> (); } }
public MailSetting MailSetting { get { return (MailSetting)ConfigurationManager.GetSection(" mailConfig"); } } Мы еще добавим MailTemplates - шаблоны которые нам понадобятся для рассылки email при регистрации, или при напоминании пароля.
|