sending mail thru asp.net using c#

Posted by Ragha under ASP.NET on 3/27/2008 | Views : 4012 | Status : [Member] | Replies : 3
hi i have written a code using c# in asp.net to send a mail but the following exception occurs

[System.Net.Mail.SmtpFailedRecipientException] = {"Mailbox unavailable. The server response was: Relay is not permitted. Configure your mail client for SMTP AUTHENTICATION"}


the code i have written is


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Net;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
public void send(string toadd,string fromadd,string sub,string body,string username,string pwd,string mailserver)
{
try
{
MailMessage m;
m = new MailMessage(toadd, fromadd);
m.Body = body;
m.Subject = sub;
SmtpClient smtpcl = new SmtpClient();
NetworkCredential nwc = new NetworkCredential(username, pwd);
smtpcl.Host = mailserver;
smtpcl.UseDefaultCredentials = false;
smtpcl.Credentials = nwc;
smtpcl.Send(m);
}
catch (SmtpException smpex)
{
Response.Write(smpex.Message.ToString());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string toadd, fromadd, body, sub,username,pwd,mailserver;
mailserver = System.Configuration.ConfigurationManager.AppSettings["SMTPMailServer"];
fromadd = System.Configuration.ConfigurationManager.AppSettings["MailFrom"];
username = System.Configuration.ConfigurationManager.AppSettings["strUserName"];
pwd = System.Configuration.ConfigurationManager.AppSettings["strPassword"];
toadd = TextBox1.Text.ToString().Trim();
sub = TextBox2.Text.ToString().Trim();
body = TextBox3.Text.ToString().Trim();
send(toadd, fromadd, sub, body, username, pwd,mailserver);
}
}




Responses

Posted by: perfectchourasia-9163 on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
http://sandeep-chourasia.blogspot.in/2011/05/send-mail-in-aspnet.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 3/28/2008 [Member] Starter

Up
0
Down
Try looking following urls

http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx

http://kbalertz.com/895853/troubleshoot-relay-issues-Exchange-Server-Exchange-Server.aspx

http://mysiteisdown.com/bouncewt.html

On another note, I think you should write your SMTP details into your web.config file and try to see if your SMTP server is really working.

Thanks


Regards,
Raja, USA

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ragha on: 3/31/2008 [Member] Starter

Up
0
Down
hi raj

i got this


thanks for the help

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response