Hello Frnds,
I have written small code for sending mail using smtp server.but i am getting exception
An exception of type 'System.Net.Mail.SmtpException' occurred in System.dll but was not handled in user code
Additional information: Transaction failed. The server response was: 5.7.1 <bhavani_glowtouch@yahoo.com>: Relay access denied
Here is my code plese tell me where is the problem
MailMessage mail = new MailMessage();mail.To.Add(
"bhavani_glowtouch@yahoo.com");MailAddress mailFrom = new MailAddress("bhavani.b@intense.in");mail.From = mailFrom;
mail.Subject = "Reuqest For Converting Preapid Sim to PostPaid Sim";mail.Body =
"Welcome to Non-Voice Service Channel Management";mail.IsBodyHtml = true; SmtpClient objMailClient = new SmtpClient();objMailClient.Host = "intensemail.no-ip.org";
objMailClient.Send(mail);
plese help me outt
![]() |
0 |
![]() |
Please check this thread for sample code to send mail using Asp.Net
http://forums.asp.net/t/971802.aspx
If this post was useful to you, please mark it as answer.
ClientSideAsp.Net | Blog
![]() |
0 |
![]() |
probably your smtp server needs to authenticate you
Hao Peng
Loving On-line Community
![]() |
0 |
![]() |
Hi
Thanks for reply.
needs to authenticate means i tried with username and password also..
Authenticate means do i need to configure my mail id in smtp server?if yes who wil do(sysadmin or we have to do?) how to do?
but same problem i am getting
any ideas
![]() |
0 |
![]() |
Here is a sample of sending mails with authentication
http://www.codeproject.com/KB/aspnet/SMTPGmail.aspx
You need an emailID (Username) and Password as credentials .
If this post was useful to you, please mark it as answer.
ClientSideAsp.Net | Blog
![]() |
0 |
![]() |
where is your smtp server? your company intranet or your local machine?
if it's your company you need to normally ask your domain admin (or the admin of that server). If it's your local machine maybe it's not set up correct.
Hao Peng
Loving On-line Community
![]() |
0 |
![]() |
try these links. They should surely solve ur solution.
aspnet.4guysfromrolla.com/articles/101707-1.aspx
articles.techrepublic.com.com/5100-10878_11-5766248.html
![]() |
0 |
![]() |
Hi
Thanks for quick reply...
Smtp server is in othersystem not in my system..i set credentials also..
but iam getting same exception
An exception of type 'System.Exception' occurred in App_Web_as1veiq8.dll but was not handled in user code
Additional information: Transaction failed. The server response was: 5.7.1 <b_sandya84@rediffmail.com>: Relay access denied
any ideas?
string CredentialName = "username"; string CredentialPassWord = "password";string MailServer = "smtp server name";System.Net.Mail.
MailMessage ObjMailMessage = new System.Net.Mail.MailMessage();SmtpClient Client = new SmtpClient(); MailAddress From = new MailAddress(CredentialName);Client.Credentials = new System.Net.NetworkCredential(CredentialName, CredentialPassWord);ObjMailMessage.To.Add(ToMailId);
ObjMailMessage.From = From;
ObjMailMessage.Subject = MailSubject;
ObjMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;ObjMailMessage.BodyEncoding = System.Text.Encoding.UTF8;ObjMailMessage.Body = Mailbody;
ObjMailMessage.IsBodyHtml = IsBodyHtml;
Client.Host = MailServer;
//Client.EnableSsl = true; try{
Client.Send(ObjMailMessage);
}
catch (System.Net.Mail.SmtpException ex){
throw new Exception(ex.Message);}
please helps me out
Thanks
sandhya
![]() |
0 |
![]() |
Hi there,
Sending a email with an attachment using ASP.NET 2.0 and C# is actually very simple.
First, you will need to import the System.Net.Mail namespace.
The System.Net.Mail namespace contains the SmtpClient and MailMessage Classes that we need in order to send the email and the message attachment.
using System.Net.Mail; |
protected void btnSubmit_Click(object sender, EventArgs e) { try } { MailAddress SendFrom = new MailAddress(txtFrom.Text); catch (Exception ex)MailAddress SendTo = new MailAddress(txtTo.Text); MailMessage MyMessage = new MailMessage(SendFrom, SendTo); MyMessage.Subject = txtSubject.Text; MyMessage.Body = txtBody.Text; Attachment attachFile = new Attachment(txtAttachmentPath.Text); MyMessage.Attachments.Add(attachFile); SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text); emailClient.Send(MyMessage); litStatus.Text = "Message Sent"; } { litStatus.Text=ex.ToString(); } |
The front end .aspx page looks something like this:
<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc"> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1"> To</td> <td bgcolor="#FFFFFF"><asp:TextBox ID="txtTo" runat="server" Columns="50"></asp:TextBox> </td> </tr> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1"> From</td> <td bgcolor="#FFFFFF"><asp:TextBox ID="txtFrom" runat="server" Columns="50"></asp:TextBox> </td> </tr> <tr> <td align="right" bgcolor="#eeeeee" class="header1"> SMTP Server</td> <td bgcolor="#FFFFFF"><asp:TextBox ID="txtSMTPServer" runat="server" Columns="50"></asp:TextBox></td> </tr> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1"> Subject</td> <td bgcolor="#FFFFFF"><asp:TextBox ID="txtSubject" runat="server" Columns="50"></asp:TextBox></td> </tr> <tr> <td align="right" bgcolor="#eeeeee" class="header1"> Attachment</td> <td bgcolor="#FFFFFF"> <asp:TextBox ID="txtAttachmentPath" runat="server" Columns="50"></asp:TextBox></td> </tr> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1"> Body</td> <td bgcolor="#FFFFFF"><asp:TextBox ID="txtBody" runat="server" Columns="40" TextMode="MultiLine"></asp:TextBox></td> </tr> <tr> <td align="right" bgcolor="#eeeeee" class="header1">Action</td> <td bgcolor="#FFFFFF"><asp:Button ID="btnSubmit" runat="server" Text="Send Email" OnClick="btnSubmit_Click" /></td> </tr> <tr> <td width="100" align="right" bgcolor="#eeeeee" class="header1">Status</td> <td bgcolor="#FFFFFF" class="basix"><asp:Literal ID="litStatus" runat="server"></asp:Literal></td> </tr> </table> |
The flow for the code behind page is as follows.
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; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) } { } protected void btnSubmit_Click(object sender, EventArgs e) { try }{ MailAddress SendFrom = new MailAddress(txtFrom.Text); }MailAddress SendTo = new MailAddress(txtTo.Text); MailMessage MyMessage = new MailMessage(SendFrom, SendTo); MyMessage.Subject = txtSubject.Text; MyMessage.Body = txtBody.Text; Attachment attachFile = new Attachment(txtAttachmentPath.Text); MyMessage.Attachments.Add(attachFile); SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text); emailClient.Send(MyMessage); litStatus.Text = "Message Sent"; catch (Exception ex) { litStatus.Text=ex.ToString(); } |
![]() |
0 |
![]() |
Hi,
Thanks for giving reply
My code is working but within my company only mail is sending outside domains like yahoo,gmail is not getting mail.
if i give to address as yahoo domain its getting exception
An exception of type 'System.Exception' occurred in App_Web_pjqka5ig.dll but was not handled in user code
Additional information: Transaction failed. The server response was: 5.7.1 <bhavani_glowtouch@yahoo.com>: Relay access denied
my requirement is i need to send mail to any domains..
Please give reply
Thanks
sandhya
![]() |
0 |
![]() |
Your SMTP may need authentication to send mails to other domains.. Please follow the source code in the http://www.systemnetmail.com/faq/4.2.aspx
You have to give a username and password from your company mail to make it work..
If the problem still persists you may need to contact your Hosting provider to know how the mailing work with ther server and most probably they will have sample code to make it work..
If this post was useful to you, please mark it as answer.
ClientSideAsp.Net | Blog
![]() |
0 |
![]() |
make sure you have the following setting on the web.config
<system.net>
<mailSettings>
<smtp>
<network host="smtp.domainname.com" port="25" userName="email@domain.com" password="password" defaultCredentials="false"/>
</smtp>
</mailSettings>
</system.net>
Hope this helps
![]() |
0 |
![]() |