EDN Admin
Well-known member
Hey,
Im trying to maintain a list of email addresses in app.config file.
What I need to change in my code in order to use more than one value for one key.
<br/>
<pre style="font-family:Consolas; background-color:white <span style="color:blue using System;
<span style="color:blue using System.Collections.Generic;
<span style="color:blue using System.Linq;
<span style="color:blue using System.Text;
<span style="color:blue using System.Net.Mail;
<span style="color:blue using System.Net.Mime;
<span style="color:blue using System.IO;
<span style="color:blue using System.Configuration;
<span style="color:blue using Microsoft.VisualStudio.TestTools.UnitTesting;
<span style="color:blue namespace Reports
{
<span style="color:blue public <span style="color:blue static <span style="color:blue class <span style="color:#2b91af autoMail
{
<span style="color:blue public <span style="color:blue static <span style="color:blue void SendMail(<span style="color:blue string attachFile)
{
<span style="color:#2b91af MailMessage m = <span style="color:blue new <span style="color:#2b91af MailMessage();
<span style="color:#2b91af SmtpClient sc = <span style="color:blue new <span style="color:#2b91af SmtpClient();
sc.Host = <span style="color:#a31515 "mail.net";
sc.Port = 25;
m.To.Add(<span style="color:blue new <span style="color:#2b91af MailAddress(<span style="color:#2b91af ConfigurationManager.AppSettings[<span style="color:#a31515 "ToMailAddress"]));
m.From = <span style="color:blue new <span style="color:#2b91af MailAddress(<span style="color:#a31515 "test@test.com", <span style="color:#a31515 "Test");
m.Subject = <span style="color:#a31515 "Test" + <span style="color:#2b91af DateTime.Now.ToString(<span style="color:#a31515 "yyyyMMdd");
m.IsBodyHtml = <span style="color:blue true;
m.Body = <span style="color:#a31515 " This is a Test Mail";
<span style="color:#2b91af Attachment a = <span style="color:blue new <span style="color:#2b91af Attachment(attachFile);
m.Attachments.Add(a);
sc.Send(m);
}
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args)
{
<span style="color:blue try
{
SendMail(<span style="color:blue null);
<span style="color:#2b91af Console.ReadLine();
}
<span style="color:blue catch (<span style="color:#2b91af Exception ex)
{
<span style="color:#2b91af Console.WriteLine(ex.Message);
<span style="color:#2b91af Console.ReadLine();
}
}
}
}[/code]
<pre style="font-family:Consolas; background-color:white <span style="color:blue <?<span style="color:#a31515 xml<span style="color:blue <span style="color:red version<span style="color:blue ="<span style="color:blue 1.0"<span style="color:blue <span style="color:red encoding<span style="color:blue ="<span style="color:blue utf-8"<span style="color:blue ?>
<span style="color:blue <<span style="color:#a31515 configuration<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 appSettings<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add<span style="color:blue <span style="color:red key<span style="color:blue ="<span style="color:blue ToMailAddress"<span style="color:blue <span style="color:red value<span style="color:blue ="test2@test.com"<span style="color:blue ""<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add<span style="color:blue <span style="color:red key<span style="color:blue ="<span style="color:blue FromMailAddress"<span style="color:blue <span style="color:red value<span style="color:blue ="<span style="color:blue test@test.com"<span style="color:blue /><span style="color:blue
<span style="color:blue </<span style="color:#a31515 appSettings<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 configuration<span style="color:blue >[/code]
<br/>
View the full article
Im trying to maintain a list of email addresses in app.config file.
What I need to change in my code in order to use more than one value for one key.
<br/>
<pre style="font-family:Consolas; background-color:white <span style="color:blue using System;
<span style="color:blue using System.Collections.Generic;
<span style="color:blue using System.Linq;
<span style="color:blue using System.Text;
<span style="color:blue using System.Net.Mail;
<span style="color:blue using System.Net.Mime;
<span style="color:blue using System.IO;
<span style="color:blue using System.Configuration;
<span style="color:blue using Microsoft.VisualStudio.TestTools.UnitTesting;
<span style="color:blue namespace Reports
{
<span style="color:blue public <span style="color:blue static <span style="color:blue class <span style="color:#2b91af autoMail
{
<span style="color:blue public <span style="color:blue static <span style="color:blue void SendMail(<span style="color:blue string attachFile)
{
<span style="color:#2b91af MailMessage m = <span style="color:blue new <span style="color:#2b91af MailMessage();
<span style="color:#2b91af SmtpClient sc = <span style="color:blue new <span style="color:#2b91af SmtpClient();
sc.Host = <span style="color:#a31515 "mail.net";
sc.Port = 25;
m.To.Add(<span style="color:blue new <span style="color:#2b91af MailAddress(<span style="color:#2b91af ConfigurationManager.AppSettings[<span style="color:#a31515 "ToMailAddress"]));
m.From = <span style="color:blue new <span style="color:#2b91af MailAddress(<span style="color:#a31515 "test@test.com", <span style="color:#a31515 "Test");
m.Subject = <span style="color:#a31515 "Test" + <span style="color:#2b91af DateTime.Now.ToString(<span style="color:#a31515 "yyyyMMdd");
m.IsBodyHtml = <span style="color:blue true;
m.Body = <span style="color:#a31515 " This is a Test Mail";
<span style="color:#2b91af Attachment a = <span style="color:blue new <span style="color:#2b91af Attachment(attachFile);
m.Attachments.Add(a);
sc.Send(m);
}
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args)
{
<span style="color:blue try
{
SendMail(<span style="color:blue null);
<span style="color:#2b91af Console.ReadLine();
}
<span style="color:blue catch (<span style="color:#2b91af Exception ex)
{
<span style="color:#2b91af Console.WriteLine(ex.Message);
<span style="color:#2b91af Console.ReadLine();
}
}
}
}[/code]
<pre style="font-family:Consolas; background-color:white <span style="color:blue <?<span style="color:#a31515 xml<span style="color:blue <span style="color:red version<span style="color:blue ="<span style="color:blue 1.0"<span style="color:blue <span style="color:red encoding<span style="color:blue ="<span style="color:blue utf-8"<span style="color:blue ?>
<span style="color:blue <<span style="color:#a31515 configuration<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 appSettings<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 add<span style="color:blue <span style="color:red key<span style="color:blue ="<span style="color:blue ToMailAddress"<span style="color:blue <span style="color:red value<span style="color:blue ="test2@test.com"<span style="color:blue ""<span style="color:blue />
<span style="color:blue <<span style="color:#a31515 add<span style="color:blue <span style="color:red key<span style="color:blue ="<span style="color:blue FromMailAddress"<span style="color:blue <span style="color:red value<span style="color:blue ="<span style="color:blue test@test.com"<span style="color:blue /><span style="color:blue
<span style="color:blue </<span style="color:#a31515 appSettings<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 configuration<span style="color:blue >[/code]
<br/>
View the full article