Sending mail using SMTP Server in


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 <>: Relay access denied

Here is my code

Dim mail_body As New StringBuilder

Dim body As String = "Welcome to Non-Voice Service Channel Management"

'create html email body

mail_body.Append("<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">")



mail_body.Append("<title>Send Email</title>")

mail_body.Append("<style type=""text/css"">")

mail_body.Append(".dblue8 { font-family:arial; color: #000066; font-size: 8pt }")



mail_body.Append("<body class=""dblue8"">")

'add in text from message box as the body




Dim Email As New System.Net.Mail.MailMessage()


Dim mailFrom As New MailAddress("")

Email.From = mailFrom

Email.Subject = "Reuqest For Converting Preapid Sim to PostPaid Sim"

Email.Body = body

Dim mailClient As New System.Net.Mail.SmtpClient()

mailClient.Host = "My SMTPHOST NAME" 'checked with my smtp server name

Email.IsBodyHtml = True



Catch ex As Exception


End Try


In the above code where is the problem im not getting.Please can anyone helps me out..



7/1/2008 7:22:37 AM 93655 articles. 6 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 27

Please check out the links:

Refre to the doc:


Please don't forget to mark the post as Answer, which helps you.

Thank you.
7/1/2008 7:49:31 AM

SMTP server is the problem, not your code. Make sure that relay is enable on SMTP server for the IP address of computer that send mail.

Best regards,
7/1/2008 7:51:34 AM

check these links for sending mail


2.Using ASP.NET to Send E-Mail—Including Attachments -


4.How to configure an Internet Information Services SMTP virtual server to archive or to remove messages in an Exchange Server 2003 test environment

5.Sending HTML Mail with Embedded Image in .NET _Embedded_Image_in_NET.all


7/1/2008 8:07:18 AM


 Thanks for giving reply..

Allow all computers which sucessfully authenticate to relay , regardless of the listefd above tat checkbox is defaultly checked...

Any ideas?






7/1/2008 9:49:01 AM

Hi there,

Sending a email with an attachment using ASP.NET 2.0 and VB.NET 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.

Imports 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 Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim SendFrom As MailAddress = New MailAddress(txtFrom.Text)
Dim SendTo As MailAddress = New MailAddress(txtTo.Text)

Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo)

MyMessage.Subject = txtSubject.Text
MyMessage.Body = txtBody.Text

Dim attachFile As New Attachment(txtAttachmentPath.Text)

Dim emailClient As New SmtpClient(txtSMTPServer.Text)

litStatus.Text = "Message Sent"
Catch ex As Exception
litStatus.Text = ex.ToString()
End Try
End Sub

The front end .aspx page looks something like this:

<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc">
<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 width="100" align="right" bgcolor="#eeeeee" class="header1"> From</td>
<td bgcolor="#FFFFFF"><asp:TextBox ID="txtFrom" runat="server" Columns="50"></asp:TextBox>
<td align="right" bgcolor="#eeeeee" class="header1"> SMTP Server</td>
<td bgcolor="#FFFFFF"><asp:TextBox ID="txtSMTPServer" runat="server" Columns="50"></asp:TextBox></td>
<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>
<td align="right" bgcolor="#eeeeee" class="header1"> Attachment</td>
<td bgcolor="#FFFFFF">
<asp:TextBox ID="txtAttachmentPath" runat="server" Columns="50"></asp:TextBox></td>
<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>
<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>
<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>

The flow for the code behind page is as follows.

Imports System.Net.Mail

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim SendFrom As MailAddress = New MailAddress(txtFrom.Text)
Dim SendTo As MailAddress = New MailAddress(txtTo.Text)

Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo)

MyMessage.Subject = txtSubject.Text
MyMessage.Body = txtBody.Text

Dim attachFile As New Attachment(txtAttachmentPath.Text)

Dim emailClient As New SmtpClient(txtSMTPServer.Text)

litStatus.Text = "Message Sent"
Catch ex As Exception
litStatus.Text = ex.ToString()
End Try
End Sub
End Class

Kalyan Krishna.B
(Web Developer)

7/1/2008 12:04:41 PM

i have similar issue in c#

It gives error as inner exception.Please help me with this


 This is the code which i used in my application


System.Net.Mail.MailMessage objEmail = new System.Net.Mail.MailMessage();


objEmail.From =
new System.Net.Mail.MailAddress("");objEmail.Subject = "Email From";

objEmail.Body = pwd;

objEmail.IsBodyHtml = false;

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("");

// smtp.Credentials = new NetworkCredential("username", "password");

//smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;



and made changes in web.config file as




<smtp deliveryMethod="Network">

<network host="localhost" port="25" defaultCredentials="true" />

</smtp> </mailSettings>


8/12/2008 1:45:44 AM

Similar Artilces:

Sending SMS using or using or
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------------------------------------------------<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns="" ><head runat="server">    <title>Untitled Page</title></head><body>    <form id="form1" runat="server">    <div>        <asp:Button ID="btnOK" runat="server" OnClick="btnOK_Click" Text="Send Email OK" />        <asp:Button ID="btnFail" runat="server" OnClick="btnFail_Click&...

Problem with sending mail using smtp server in
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 <>: Relay access denied   Here is my code plese tell me where is the problemMailMessage mail = new MailMessage(); mail.To.Add("");MailAddress mailFrom = new MailAddress(""); mail.From = ...

Send e-mail with web form values (
I'm sure this is very simple but;I have a form with numerous (<50) textbox controls and related Label controls; ie: <asp:Label ID="Label1" runat="server" Text="Last Name: "></asp:Label> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>When the form is submitted I want to loop through each label control and textbox control and get their Text values for the e-mail without specifying each control. Anyone have suggestions on the best way to do this?Any assistance appreciated greatly!   Here is a solution for you in

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, web.config settings are as follows <>    <mailSettings>      <smtp from=""&g...

.Net 2.0 Web application using is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one web application using which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

E-mail form data using authenticated smtp relay (
Hi, out there, I have a set of forms on my site that work fine e-mailing the data back to me with the free e-mail frommy current host, whose smtp relays do not require authentication.  However, there's a tight limit on the number of relays I can have a day.  Due to traffic, I would like my forms now to reference another "From" e-mail, from host with unlimited smtp relays.  Unfortunately, their e-mail requires authentication, and having combed these posts for hours, as well as others, I can't find a working solution to my problem.  It's more...

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 1.1, i also have a new app that use 2.0.  how can i set my new .NET 2.0 app to point to 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 which has IIS 5.0.  I do not see any default websites/virtual directories/ or any type of ASP.NET tab.  I just dont' know how to get my program to run using .NET framework 2.0. On win2k it is a mess sometimes to get this working, well first install .net framework 2.0 on the server, then see if iis mappings are correct. publish the website and then right click properties->select 2.0. from the dropdown.  Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations...

Help sending mail using
i want to send an email notification from my application.The code i used is Dim mail As New MailMessage mail.To = "" mail.From = "" mail.Subject = "this is a test email." mail.Body = "this is my test email body" SmtpMail.SmtpServer = "" SmtpMail.Send(mail)I am not getting any error.But the mail is undelivered.Help Pls if that from local host or in the server ?have a look at my code that i already have in my website Alnassar | FREE Nodil Tab Controlhttp://www.mefranchising...

Deploying Vb.Net Web Forms on the server
I created a setup file for my first test Web Application. It has a few forms that I like to test on the server. What do I have to do on the server for it to work properly. I have it working on my dev machine. What do I have to install and is there any changes that I have to make to machine.config or any other files. I am using the default settings in Global and web.config files. These files were generated by the Vb.Net 2003. I have been reading on this for awhile and like to make sure of the steps I have to follow. Any help will be greatly appreciated....

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->to(""); $smtp->data(); $smtp->datasend("To:"); $smtp->datasend("From: \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...

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 = '' || '' ; my $sub = '' || 'this is a testmail'; my $content = '' || 'this is a data'; my $to; my $relayhost = '' || 'localhost'; GetOptions( 'fro...

Send E-mail using VB.NET
Hi, Does someone know how I could send emails in bulk to registered users from a web interface? I have a website where users can register on and have created a sort of CMS tool, where users can add some text to the website like a Word editor text box and all this information is stored in an SQL DB.So, I created a field e-mail address and all the e-mail addresses are available in my database. Once a month, I would like to send an email to all the registered users avaialable in the DB. So I would like to have a TO: field where I can add multiple email addresses in, by selecting the users fr...

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...

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 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 developing. The trick is to use the "Src" attribute of the @Page directive. Check out the link if you are inclined. You are welcome to download the code if you are interested further, found at the same link. (Note that the reason that I looked for a way to do this is because I wanted to have the option to include some VB.NET-based demos at my site. Since my site is a C#.NET ASP.NET, I was told that there was no want to do this. Therefore, I looked for a workaround and just happened to find one.) Enjoy (and then get back to work!) you are right !!!mixing languages could cause unknow and uncontrolled problems !!! if a developer has to mix ....the practical way is to create a new project with different language and what will be absolutely fine !!!thanks mkamoski for raising this issue !!Fadil Alnassar | FREE Nodil Tab Controlhttp://www.mefranchisi...

Send Email from form using
Please see code behind below. This my message is being received by only with hard coded text of subject with no body.  How do I correct my syntax so that the information is passed from form fields to email message?  The form data is being inserted into the db and redirected to .aspx page.  Just need to get data from for fields to message.  -------------------------------------------- Imports System.Net.MailPartial Class apps_contactpage Inherits System.Web.UI.PageSub Send2Mail(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs) 'create the mail...

Problem With sending an e-mail using VB.NET
hey guys,   i have a problem with send an smtp mail using VB, i tried to solve this problem but it always gives me a message that the user is not authenticated, although i provide my password, but still it is not working, this is the message that i got every time i tried it: The SMTP server requires a secure connection or the client was not authenticated. Authentication Required here is the code im using: Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.ClickDim fromAddress As String = txtFrom.Text Dim toAddress As String...

To send mail thru SMTP using
Sir Please help me Sir . I developed one program to send mail to General Manger when other manager requesting the holiday . I used MAPI mailsession . But that program is not working in some of the machine of Managers having outlook express with SMTP . But from some machine the mail automatically send to General manager without any problem. So I am trying to change the code to send the mail thru SMTP . I wrote a simple program in the similar way of the code in Sybase codexchange .Net Interop. I am using PB11.1.That program exe is working in my machine . When I try to run th...

Edit email body before sending mail using
Code to Edit email body before sending mail to end users.Email body should contain username, Attached doc's list and some text.Any one plz in Thank you How far have you got with doing this yourself?  Are you getting error messages that you don't understand?  Have you developed the form to accept the initial text prior to allowing it to be edited?  If you have, all you need to do is display it in an editable format. Regards Mike [MVP - ASP/ASP.NET]My site You can try to create a email template for modifing when you send the email. hence you can replace ...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Converting Web Site from Vb.Net 2003 to Vb.Net 2005
I have a web site in 2003 that I what to convert to 2005. I open my web site in the visual studio 2005 by Local IIS option. I follow the steps of the visual studio conversion wizard.In the conversion report I received the following warning 'Referencepath' settings have not been converted.  Can anyone tell what I have to do to make this warning disappear? Best regards,Sérgio 'Referencepath'  is a property you can set with with VS2003 project file, sothat when ever you to do Add reference this path is serached for class libraries.  We do not  have that ...

use of and
i make a small website using,  in it i make a 2 class in that i want to use in that website, i dont know how to call that class. let your class is  - class clsMyClass    {        public void myFunction()        {            // do something        }    } now the first way - create objectclsMyClass myObj = new clsMyClass();myObj.myFunction(); // call function================...

RE: How to send files as Attachements to mail using Net::SMTP o n windows
madhu, here is the code for sending attachments. ------------------------------------------------ $sender->OpenMultipart({to => '', subject => ' - new module'}); $sender->Body; $sender->SendEnc(<<'*END*'); Here is a new module Mail::Sender. It provides an object based interface to sending SMTP mails. It uses a direct socket connection, so it doesn't need any additional program. Enjoy, Jenda *END* $sender->Attach( {description => 'Perl ...

Web resources about - Sending mail using SMTP Server in -

Sending/receiving relationship - Wikipedia, the free encyclopedia
A sending/receiving relationship is one in which a public school district sends some or all of its students to attend the schools of another ...

U.K. Woman Faces 20 Months For Creating Fake Facebook Accounts, Sending Herself Abusive Messages
A woman in Cornwall in the U.K. came up with a creative way to use Facebook to accelerate a family spat, and it earned her 20 months in prison. ...

CHVRCHES - Dear guys, Please stop sending us emails like... - Facebook
Dear guys, Please stop sending us emails like this. This is one of the more polite ones. Other recent classics include "I'm going to give her ...

Facebook Sending Perez Hilton More Traffic than Google, Driving 3.3% of All US Traffic to Video Sites ...
For media companies evaluating their Facebook marketing strategy , here’s an interesting sign of the times: web analytics firm Hitwise is reporting ...

A better experience for sending Tweets and DMs - Twitter Blog
... panel New Tweet panel in da...... Skip to main content Blog Got an account? Sign in Search form Search &nbsp A better experience for sending ...

How to Go From Working 60 Hours a Week to 40 By Sending 2 Emails a Week
I’m convinced 95% of cubicle workers who work over 60 hours a week constantly can cut it down to 40-45 hours by sending 2 emails a week to their ...

Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the ...
Get Live Emoji - sending GIF Animation Emoji for Zoosk,Skype,Kik,Whatsapp,Facebook Messenger Etc. on the App Store. See screenshots and ratings, ...

Cynthia McKinney - responds to Obama on sending troops into Afghanistan - Debate Answer - YouTube
Cynthia McKinney, Green Party Presidential candidate, responds to Barack Obama on his support for sending troops into Afghanistan. Based on his ...

'Shark' providers sending unskilled workers to high-risk sites, say trainers
&#8203;West Australian training companies say dodgy providers they describe as 'sharks' and 'cowboys' are flooding high-risk mine sites with ...

Resources last updated: 3/10/2016 7:25:38 PM