PDA

View Full Version : Sending e-mail using SMTP on DiscountASP.NET


BlasterV
04-21-2008, 10:18 AM
I have tested this code on a different SMTP server and it worked fine, but it doesn't work with the smtp server listed on my discountASP.NET hosting account.

Anyone know if I have to do anything special?

domainnamefromdiscountasp is replaced by the domain name obviously :-D

[quote]

publicstaticStringserver='smtp.domainnamefromdisco untasp.com';

Amethod(){

MailMessagemsg=newMailMessage();

msg.From=newMailAddress(from);
msg.Subject=subject;
msg.Body=body;
msg.Priority=createPriority();

msg.IsBodyHtml=true;

SmtpClientsmtp=newSmtpClient(server);

IEnumeratore=recipents.GetEnumerator();

while(e.MoveNext())
{
msg.To.Add(e.Current.ToString());
try
{
smtp.Send(msg);
}
catch(Exceptionex)
{
Console.Error.WriteLine('Anerroroccuredtryingtosen dthismessage.'+'\n'+ex.Message);
}
msg.To.Clear();
}
}
</CODE>

This is method (and its class) is part of a C# library project we use in our web application, which is powered by C# back-end code and written in ASP.NET 3.5

wisemx
04-21-2008, 10:22 AM
Instead of the smtp domain have you tried localhost ?

BlasterV
04-22-2008, 01:20 AM
That did it, Thank you!

Benja
05-06-2008, 01:07 AM
Thanks wisemx, I'm gonna check it out. Anyway I don't think that that empty string is generating the error. Its only used in the body string...

Benja
05-06-2008, 03:13 AM
I have these two methods, one works perfect but the other thst is almost the same is throwing me "No such user here". I really can't tell why if the other method works fine on the server.

Here's the code:




public static string SendCustomerMail(string name, string from, string to, string body)


{


string emailStatus;


mMail = new MailMessage();


mMail.From = new MailAddress("contacto@tusprofes.com", "TusProfes");


mMail.To.Add(to);


mMail.IsBodyHtml = true;


mMail.Subject = "contacto TusProfes:";


mMail.Body = "<html><p>Estimado Profesor:</p><p>Has recibido un correo de "


+ name + "(" + from + "), quien dice: [b]" + body + "</p></html>";


try


{


SmtpClient sClient = new SmtpClient("localhost");


sClient.Send(mMail);


emailStatus="El correo ha sido enviado satisfactoriamente.";


}


catch (Exception e)


{


emailStatus = "Ha ocurrido un error en el envˇo: "+e.Message;


}


return emailStatus;


}


Can anyone help me?

wisemx
05-06-2008, 11:39 AM
In this public function name is an empty string.