salve, ho realizzato una form in c# che mi consente di inviare dati a un indirizzo di posta, l'smtp e il destinatario sono scritti nel codice.
volevo sapere come posso fare per andare a leggere questi parametri direttamente dal web config. Nel <mailSettings> del web config ho però un'altra configurazione che uso per altri form, quindi non vorrei usarla. Grazie!!
code:
void SendEmail(string status)
{
try
{
MailMessage oMsg = new MailMessage();
oMsg.BodyFormat = MailFormat.Html;
oMsg.Subject = "Richiesta informazioni";
oMsg.Body = "<html><body>";
if (status == "GUEST")
{
oMsg.To = EmailTB.Text;
oMsg.From = "from@mail.com";
oMsg.Body += "
messaggio consegnato</p>";
}
else
{
oMsg.Headers.Add("Reply-To", EmailTB.Text);
oMsg.To = "from@mail.com";
oMsg.From = "from@mail.com";
oMsg.Body += "Hai ricevuto una richiesta informazioni.";
oMsg.Body += "Richiedente:</p>
";
oMsg.Body += "Indirizzo: " + Server.HtmlEncode(indirizzo.Text);
oMsg.Body += "
CAP: " + Server.HtmlEncode(cap.Text);
oMsg.Body += "
Città: " + Server.HtmlEncode(citta.Text);
}
oMsg.Body += "</body></html>";
SmtpMail.SmtpServer = "smtp.server.it";
SmtpMail.Send(oMsg);
oMsg = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}