enrique_aeo
asked on
send mail from app.net
i have web App
i need send email after SAVE in the database
I'm using a code that uses my email and password, is there any way to use a smtp unauthenticated
this code in web.config
<add key="MailUser" value="elopezh@smi.com.pe" />
<add key="MailUserPass" value="inicio01" />
<add key="MailServer" value="smtp.office365.com" />
<add key="MailServerPort" value="587" />
<add key="MailServerSSL" value="1" />
--- this is the class
public static bool EnviarCorreo(MailModel correo)
{
try
{
Log.WriteLogInfo("Inicio Enviar correo");
//tomar los datos de conexion del webconfig
string flgenviarcorreo = System.Configuration.Confi gurationMa nager.AppS ettings["F lgEnviarCo rreo"];
string mailuser = System.Configuration.Confi gurationMa nager.AppS ettings["M ailUser"];
string mailuserpass = System.Configuration.Confi gurationMa nager.AppS ettings["M ailUserPas s"];
string mailserver = System.Configuration.Confi gurationMa nager.AppS ettings["M ailServer" ];
string mailserverport = System.Configuration.Confi gurationMa nager.AppS ettings["M ailServerP ort"];
string mailserverssl = System.Configuration.Confi gurationMa nager.AppS ettings["M ailServerS SL"];
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
mail.From = new MailAddress(mailuser);
mail.Subject = correo.Asunto;
mail.Body = correo.MensajeHtml;
mail.Priority = MailPriority.High;
string palinBody = correo.MensajeTexto;
AlternateView plainView = AlternateView.CreateAltern ateViewFro mString(pa linBody, null, "text/plain");
// then we create the Html part to embed images,
// we need to use the prefix 'cid' in the img src value
string htmlBody = correo.MensajeHtml;
AlternateView htmlView = AlternateView.CreateAltern ateViewFro mString(
htmlBody, null, "text/html");
// add the views
mail.AlternateViews.Add(pl ainView);
mail.AlternateViews.Add(ht mlView);
SmtpClient clienteenvio = new SmtpClient();
clienteenvio.UseDefaultCre dentials = false;
clienteenvio.DeliveryMetho d = SmtpDeliveryMethod.Network ;
clienteenvio.Credentials = new NetworkCredential(mailuser , mailuserpass);
clienteenvio.Host = mailserver;
clienteenvio.Port = Convert.ToInt32(mailserver port);
clienteenvio.EnableSsl = false;
if (mailserverssl == "1")
{
clienteenvio.EnableSsl = true;
}
try
{
clienteenvio.Send(mail);
Log.WriteLogInfo("Se envio el mensaje de correo " + mail.To[0].Address);
return true;
}
catch (Exception ex)
{
Log.WriteLogError(ex.Messa ge);
return false;
}
}
catch (Exception ex)
{
Log.WriteLogError(ex.Messa ge);
throw ex;
}
}
in App web
if (DAL_Solicitud.Guardar(ref solicitud))
{
MailModel resul = new MailModel();
resul.Para.Add("elopezh@sm i.com.pe") ;
if (model.emp_inv_des == "10359") resul.CC.Add("pchanca@smi. com.pe");
resul.MensajeTexto = "Prueba de envio de correo: MensajeTexto";
resul.MensajeHtml = "<table>" +
"<tr><td style='font-weight:bold'>P royecto:" + "</td><td>" + solicitud.proyecto + "</td>" + "</tr>" +
"<tr><td style='font-weight:bold'>S olicita:" + "</td><td>" + solicitud.emp_comercial + "</td>" + "</tr>" +
"<tr><td style='font-weight:bold'>E mpresa:" + "</td><td>" + solicitud.empresa + "</td>" + "</tr>" +
"</table>";
resul.Asunto = "Solicitud de Proyecto";
VTRUtil.EnviarCorreo(resul );
return Json(new { coderror = solicitud.coderror, msgerror = solicitud.msgerror });
}
i need send email after SAVE in the database
I'm using a code that uses my email and password, is there any way to use a smtp unauthenticated
this code in web.config
<add key="MailUser" value="elopezh@smi.com.pe"
<add key="MailUserPass" value="inicio01" />
<add key="MailServer" value="smtp.office365.com"
<add key="MailServerPort" value="587" />
<add key="MailServerSSL" value="1" />
--- this is the class
public static bool EnviarCorreo(MailModel correo)
{
try
{
Log.WriteLogInfo("Inicio Enviar correo");
//tomar los datos de conexion del webconfig
string flgenviarcorreo = System.Configuration.Confi
string mailuser = System.Configuration.Confi
string mailuserpass = System.Configuration.Confi
string mailserver = System.Configuration.Confi
string mailserverport = System.Configuration.Confi
string mailserverssl = System.Configuration.Confi
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
mail.From = new MailAddress(mailuser);
mail.Subject = correo.Asunto;
mail.Body = correo.MensajeHtml;
mail.Priority = MailPriority.High;
string palinBody = correo.MensajeTexto;
AlternateView plainView = AlternateView.CreateAltern
// then we create the Html part to embed images,
// we need to use the prefix 'cid' in the img src value
string htmlBody = correo.MensajeHtml;
AlternateView htmlView = AlternateView.CreateAltern
htmlBody, null, "text/html");
// add the views
mail.AlternateViews.Add(pl
mail.AlternateViews.Add(ht
SmtpClient clienteenvio = new SmtpClient();
clienteenvio.UseDefaultCre
clienteenvio.DeliveryMetho
clienteenvio.Credentials = new NetworkCredential(mailuser
clienteenvio.Host = mailserver;
clienteenvio.Port = Convert.ToInt32(mailserver
clienteenvio.EnableSsl = false;
if (mailserverssl == "1")
{
clienteenvio.EnableSsl = true;
}
try
{
clienteenvio.Send(mail);
Log.WriteLogInfo("Se envio el mensaje de correo " + mail.To[0].Address);
return true;
}
catch (Exception ex)
{
Log.WriteLogError(ex.Messa
return false;
}
}
catch (Exception ex)
{
Log.WriteLogError(ex.Messa
throw ex;
}
}
in App web
if (DAL_Solicitud.Guardar(ref
{
MailModel resul = new MailModel();
resul.Para.Add("elopezh@sm
if (model.emp_inv_des == "10359") resul.CC.Add("pchanca@smi.
resul.MensajeTexto = "Prueba de envio de correo: MensajeTexto";
resul.MensajeHtml = "<table>" +
"<tr><td style='font-weight:bold'>P
"<tr><td style='font-weight:bold'>S
"<tr><td style='font-weight:bold'>E
"</table>";
resul.Asunto = "Solicitud de Proyecto";
VTRUtil.EnviarCorreo(resul
return Json(new { coderror = solicitud.coderror, msgerror = solicitud.msgerror });
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it is comment, but not send mail
do you get any error?
ASKER
THIS IS THE ERROR
Message "Server does not support secure connections." string
Source "System" string
StackTrace " at System.Net.Mail.SmtpConnec tion.GetCo nnection(S ervicePoin t servicePoint)\r\n at System.Net.Mail.SmtpTransp ort.GetCon nection(Se rvicePoint servicePoint)\r\n at System.Net.Mail.SmtpClient .GetConnec tion()\r\n at System.Net.Mail.SmtpClient .Send(Mail Message message)\r\n at srvvtr.VTRUtil.EnviarCorre o(MailMode l correo) in
WEB.CONFIG
<!--Configuracion de Correo-->
<add key="FlgEnviarCorreo" value="1" />
<add key="MailUser" value="sistemas@smi.com.pe " />
<add key="MailUserPass" value="Pa$$w0rd02" />
<add key="MailServer" value="smtp.smi.com.pe" />
<add key="MailServerPort" value="25" />
<add key="MailServerSSL" value="1" />
Message "Server does not support secure connections." string
Source "System" string
StackTrace " at System.Net.Mail.SmtpConnec
WEB.CONFIG
<!--Configuracion de Correo-->
<add key="FlgEnviarCorreo" value="1" />
<add key="MailUser" value="sistemas@smi.com.pe
<add key="MailUserPass" value="Pa$$w0rd02" />
<add key="MailServer" value="smtp.smi.com.pe" />
<add key="MailServerPort" value="25" />
<add key="MailServerSSL" value="1" />
ASKER
this is the problema
<add key="MailServerSSL" value="1" />
i change <add key="MailServerSSL" value="0" />
<add key="MailServerSSL" value="1" />
i change <add key="MailServerSSL" value="0" />
ASKER
<add key="MailServerPort" value="25" />
<add key="MailServerSSL" value="0" />
<add key="MailServerSSL" value="0" />
ASKER
SmtpClient clienteenvio = new SmtpClient();
clienteenvio.UseDefaultCre
clienteenvio.DeliveryMetho