Problem with sending mail using smtp server in c#.net

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
sandhyabhavani
7/1/2008 9:01:56 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

11 Replies
1055 Views

Similar Articles

[PageSpeed] 38

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
anzer
7/1/2008 9:08:33 AM
probably your smtp server needs to authenticate you

Hao Peng

Loving On-line Community
0
hao
7/1/2008 9:19:48 AM

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
sandhyabhavani
7/1/2008 9:29:11 AM

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
anzer
7/1/2008 9:32:56 AM

 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
hao
7/1/2008 9:33:29 AM

try these links. They should surely solve ur solution. 

http://devlicio.us/blogs/mike_nichols/archive/2008/05/07/configuring-iis-6-0-to-send-mail-via-smtp-for-asp-net-applications.aspx

aspnet.4guysfromrolla.com/articles/101707-1.aspx

articles.techrepublic.com.com/5100-10878_11-5766248.html

 

0
itsumapathyk
7/1/2008 9:55:27 AM

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
sandhyabhavani
7/1/2008 10:00:14 AM

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;

We use the btnSubmit_Click event to do the work.

We then call the emailClient.Send to send the message using the variables from our ASP.NET coded page.

The txtAttachmentPath.Text Texbox provides the path to the file to attach to the email message.

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();
}
}

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();
}
}
}


Kalyan Krishna.B
(Web Developer)

Email: kalyandotnetdeveloper@gmail.com
0
kalyan1982
7/1/2008 10:26:18 AM

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
sandhyabhavani
7/1/2008 12:10:19 PM

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
anzer
7/1/2008 12:44:03 PM

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
MesfinReda
9/29/2008 3:55:40 PM
Reply:

Similar Artilces:

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Why do Sending SMTP Authenticated E-mail succeed using SmtpMail.Send() function but fail using SmtpClient.send() function ? Bugs in System.Net.Mail.SmtpClient when send a Authenticated E-mail?
I click btnOK button, the email can send OK, but click btnFail button,  the following error is displayed! why ? you can test the section code. The SMTP, username, password are valid!  Many thanks! "Syntax error, command unrecognized. The server response was: authentication failed,decode user password error" I have tested some other SMTP, somes is OK. I think there are some bugs with System.Net.Mail.SmtpClient when send a Authenticated E-mail with some SMTP!   //------------------------------------------.ASPX Code----------------------------------------...

Sending mail using SMTP Server in vb.net
Hi I have written small code for sending mail using smtp sevrer in vbnet.but i am getting some 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 codeDim mail_body As New StringBuilder Dim body As String = "Welcome to Non-Voice Service Channel Management" 'create html email bodymail_body.Append("<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4....

cannot send email from webpage using System.Net.Mail on external smtp server
Every time I am trying to send email from my webpage, or using passwordrecovery tool , i get following error :: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed I went through all the existing posts, but none of them worked for me. I have already checked http://www,systemwebmail.com/ web.config settings are as follows <system.net>    <mailSettings>      <smtp from="noreply@allure.com"&g...

Problem in sending mail using system.net.mail
I am using C# and ASP.Net2.0 for sending mail. But my problem is it is not being sent. I am not being able to understand it. I am using my gmail account for it. I am using System.Net and System .Net.Mail for sending the same. But i am getting the error ''Failure Sending Mail. Cannot connect to the server" . I have internet connection. Plz help me. It's urgent. I am attaching my code.  MailMessage mailMsg = new MailMessage();MailAddress ma = new MailAddress(username@gmail.com); mailMsg.From = ma; mailMsg.To.Add(s);mailMsg.Subject = "Your...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

How to get new web app to use .NET 2.0 on Win2K server using .NET 1.1 as default framework?
I have .net framework1.1 and 2.0 on our server running win2K. i have existing applications that uses asp.net 1.1, i also have a new app that use ASP.net 2.0.  how can i set my new .NET 2.0 app to point to asp.net 2.0 without messing up my existing .NET 1.1 apps? To specify the ASP .Net version fro a web application, do the followingIn IIS Manager select the web application -> Properties -> ASP.Net TabSelect  ASP.Net version you want to use for the applicationRegards,PrashantDont forget to click "Mark as Answer" on the post that helped you. But I am running Win2K...

Developed C#.net WebService 1.1 for Client C#.net 1.1. Getting error "Server was unable to process the Request" Pls Help
Hi., I developed Microsoft C#.net Web Services2003 for the Client Application C#.net 2003. When it runs in 5 machines it gives good performance and has no errors. But if i run the same application in about 80 client machines. Getting error "Server was unable to process the request". I use Sql Server 2005 as my database. I get error even when i login at a time for about 25 users. Tried modifying machine.config too. But went unsuccessful. Live Server is 2003 using IIS 6.0 I use very expensive data handling.  Its very urgent pls help. Have to post in Live Server. Thank u., ...

sending mail using Net::SMTP client
Hi, I am trying to send a mail via Net::SMTP The code is below ==================================== $smtp = Net::SMTP->new("smtp.domain.com"); $smtp->to("sd@sd.com"); $smtp->data(); $smtp->datasend("To: sd@sc.com"); $smtp->datasend("From: sd@cs.com \n"); $smtp->datasend("Subject: whatever"); $smtp->datasend("\n"); $smtp->datasend("test message"); $smtp->dataend(); ======================================== Can anybody help me out and tell me where is the error. I am using Win...

Cannot send E-Mail using C# .NET
I tried two different concepts, but both don't work. Any idea?: System.Web.Mail.MailMessage Mailer = new System.Web.Mail.MailMessage(); Mailer.From = From; Mailer.To = To; Mailer.Subject = Subject; Mailer.Body = Body; Mailer.BodyFormat = Format; System.Web.Mail.SmtpMail.Send(Mailer); throws an System.Runtime.InteropServices.SEHException SmtpMail snail=new SmtpMail(); snail.Send("adress","adress", "subect","text"); causes an security exception ( CS0122: Auf 'System.Web.Mail.SmtpMail.SmtpMail()' ist der...

Problem With Sending mail Using SMTP Server
Hi Friends, I hav written small code for sending mail using SMTP Server in ASP.NET With C#. In my code if i mention to address is my company mailid.mail is going properly. if i mention to address as gmail,yahoo ids it is getting exception relay access denied main thng within the company only mail going.using outside domain mail s not going Any option to send mail with outside domains also..   Thanks sandhya       Hi,        This happens to a most of the corporate emails. I guess you must be using SMPT as your corporate serve...

Getting mail to work using Net::SMTP
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C507CB.3E975DB0 Content-Type: text/plain Hello Bugzilla Perl Gurus! I've modified the BugMail.pm to use Net::SMTP as per the instructions found at: http://www.bugzilla.org/docs/2.18/html/os-specific.html When I try to run Bugzilla I receive the following error: CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: Global symbol &qu...

using Net::SMTP unable to send out a mail
--000e0cd150b6f305fa0494363e82 Content-Type: text/plain; charset=ISO-8859-1 HI i wrote a small simple script using Net::smtp however my local MTA is not accepting the mail here is the script : ================================================= #!/usr/bin/perl use strict; use warnings; use Net::SMTP; use Getopt::Long; my $from = '' || 'system@server1.com' ; my $sub = '' || 'this is a testmail'; my $content = '' || 'this is a data'; my $to; my $relayhost = '' || 'localhost'; GetOptions( 'fro...

Sending Mail Using System.Net.Mail with out using User credentials
HI, I have an application where in i send mails based on some condition, the user is already authenticated, so i need not check the User Credentials.Right now this is how the piece lokks:- mailClient.Credentials = new NetworkCredential(USERID, USER_PWD,DOMAIN); I want to send the mail, with out validating the user credentials, Can i skip the above line. Please post aqlong with the sample code.   Thanx in Advance. Anil Kumar.   I think you cannot skip. but store user credentials in session variables after login and then pass.If this post was useful to you, please mark it as...

Web resources about - Problem with sending mail using smtp server in c#.net - asp.net.getting-started

Problem novel - Wikipedia, the free encyclopedia
Working class, or proletarian novels are often also social problem novels . This was in many ways a reaction to rapid industrialization , and ...

The problem with using infrastructure to stimulate an economy
The immediate boost to the economy from infrastructure stimulus spending is minimal, while the cost for any new jobs it creates can be huge

The problem with “bringing the country together”
... our country needs is to reject the very premise of politics. The disparate factions in the United States don’t even agree on what our problems ...

Apple confirms bug that makes the iPhone’s most frustrating problem even more frustrating
... as and satisfied as they are though, we doubt any iPhone user would make the claim that his or her handset is perfect. No, iPhones have problems ...

A recurring problem in 'Making A Murderer' used to be huge in the UK — and the country figured out how ...
... Act of 1984 [PACE], however, subsequently required officers to videotape their interviews, among other provisions. It nearly solved the problem. ...

The problem with Chinese data...
John Rutledge, Safanad chief investment strategist, shares his thoughts on China's GDP and real economic growth. And Mike Santoli, CNBC senior ...

‘Degrassi: Next Class’: “The Drugs Have Changed But The Problems Are Still The Same”
Degrassi is known for tackling the complex issues that high school students face. Subjects such as teen pregnancy, drugs, school shooting and ...

Fujitsu wants to fix Japan's deer problem with software
Fujitsu is teaming up with a Japanese forest research institute to learn how animal populations grow. The pair will look into Sika deer, a creature ...

Free Basics, net neutrality, and the problem with charity
This must have been a pretty bad year for Mark Zuckerberg. He thought he'd be a hero, but now he's a pariah. Why?

We've Already Solved Oxfam's Little Inequality Problem
The World Economic Forum at Davos is fast approaching so Oxfam has decided to re-release their report screaming that we're all going to hell ...

Resources last updated: 1/18/2016 11:38:39 PM