Trying to send an email from a web form

I'm trying to send an email from a web form:

 

MailMessage Msg = new MailMessage();

Msg.To.Add(new MailAddress(ToPerson));

Msg.From = new MailAddress(FromPerson);

Msg.Subject = Subject;

Msg.Body = BodyText;

Msg.BodyEncoding = System.Text.
Encoding.UTF8;

Msg.SubjectEncoding = System.Text.Encoding.UTF8;

Msg.Attachments.Add(new Attachment(FileName));

SmtpClient Client = new SmtpClient("127.0.0.1");

Client.Send(Msg);

I get  the exceptions:

Unable to send email

Unable to connect to remote server

 What should I be specifying as the remote server for the smtp client?  I have been using the localhost ip address.

 Some of the online help I've looked at suggests using the IIS server name, but I'm doing this in the microsoft visual studio environment, so I don't have IIS running as a service.

 Any ideas?

0
werner
1/2/2008 8:58:19 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

10 Replies
861 Views

Similar Articles

[PageSpeed] 50

Do you have an smtp server running on your development machine?


Mark this post as the "Answer" if it was the answer.
0
sswanner1
1/2/2008 9:01:50 PM

Not that I am aware of.  I'm developing using Microsoft visual studio 2005 ide and Oracle in a standalone environment.  I haven't explicitly run IIS or any other services (other than Oracle). I'm new to .net programming.  I've been working with netbeans/java/tomcat up until a couple of months ago.

0
werner
1/2/2008 9:06:51 PM

You can check with your internet supplier and get their server IP address as an alternative.


Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
0
SKVSKV
1/2/2008 9:09:43 PM

I tried using my internet provider's smtp server (smtphm.sympatico.ca)

I get the following error: 

[System.Net.Mail.SmtpException] = {"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first"}

From the code I have for sending an email, I do not know how to set up a secure connection or pass authentication information from the client to the smtp server.  (I used outlook express for email on my pc).

Do I need to run  a standalone smtp client on my pc?

 

 

 

0
werner
1/2/2008 9:25:33 PM

This is not the correct address probably.

When you try to ping this, the request times out. That means you are not communicating with that server. Check this name with your internet supplier.

 

ping smtphm.sympatico.ca    - This request times out.


Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
0
SKVSKV
1/2/2008 9:36:20 PM

It is your SMTP Client name. Otherwise I tested your code with my SMTP Client, it works fine.


Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
0
SKVSKV
1/2/2008 9:45:35 PM

Did

ping smtphm.sympatico.ca

word for you in command line window. If not, then your SMTP name is not correct.


Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
0
SKVSKV
1/4/2008 5:50:12 AM

werner.reiche:

I tried using my internet provider's smtp server (smtphm.sympatico.ca)

SmtpClient Client = new SmtpClient("127.0.0.1");

 

Hi werner.reiche,

I'm confusing. Stick out tongue Whichever SMTP do you use?

Base on my experience, there is no SMTP server on your computer, please refer the following article to configure SMTP:

http://msdn2.microsoft.com/fr-fr/library/8b83ac7t.aspx

The article title is "How to: Install and Configure SMTP Virtual Servers in IIS 6.0", and see the introduction:

In order to send e-mail from an ASP.NET Web application, you must have the Simple Mail Transfer Protocol (SMTP) service of Internet Information Services (IIS) installed and configured on your server. The IIS SMTP service is a simple component for forwarding e-mail messages to an SMTP server for delivery.



Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
1/4/2008 6:00:38 AM

Hi,

   Go through with this code

MailMessage msg = new MailMessage();
        msg.To.Add(new MailAddress(txtTo.Text));
        msg.From =new MailAddress(txtFrom.Text);
        msg.Subject = txtSubject.Text;
        msg.Body = txtMasg.Text;
        if (FileUpload1.HasFile==true)
        {
            msg.Attachments.Add(new System.Net.Mail.Attachment(FileUpload1.PostedFile.InputStream,FileUpload1.PostedFile.FileName));
        }

                try
        {
             SmtpClient objsm = new SmtpClient("10.1.68.17");  //Smtp mail server IP
          
           // objsm.DeliveryMethod = SmtpDeliveryMethod.Network;

            NetworkCredential objcre = new NetworkCredential("userid", "password"); // metinon the user id and password of that user
           // objsm.Credentials = (System.Net.ICredentialsByHost)System.Net.CredentialCache.DefaultCredentials;
          //  objsm.UseDefaultCredentials = false;
            objsm.Credentials = objcre;
            objsm.Send(msg);
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        } 

______________________________________________________________________

If this one helps you Mark as Answer.

0
alladi
1/4/2008 6:26:59 AM

Being able to specify user id was the missing link.

 Also, there's something strange with the way sympatico smtp mail servers are accessed / used by outlook express.  The one specified in outlook is smtphm.sympatico.ca, but it cannot be pinged.  If I use one of the alternatives I found using google,  smtp8.sympatico.ca, it does work.

 Thank you to all of you who provided help with this.

0
werner
1/4/2008 1:41:45 PM
Reply:

Similar Artilces:

Submitting Web forms fields to sql database by clicking on SUBMIT FORM and sending the form fields to email box
I have a created or designed a form to be stored in a SQL database table and at the same time when a user clicks on SUBMIT button the form fields will automatically goto the visitor email address immediately. Also i have created a database with tables for each of this forms Pls help i have over 10 forms designed but the problem of submitting them to the table database and the user email address is the challenge now.... You ned to familiarise yourself with the basics of database access in ASP.NET.  There are free tutuorials here: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/da...

send web email from web form error help
Hi, When send email with attachment from web form. I got an error message as below. What it is? Can someone help? Server Error in '/dotNet' Application. -------------------------------------------------------------------------------- The transport lost its connection to the server. Hi There, Please check the following link The transport failed to connect to the server Hope this helps Sunny NAGIProper Preparation Prevents Poor PerformanceDont forget to click "Mark as Answer" on the post that helped you....

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Trying to send an email from a web form #2
I'm trying to send an email from a web form:  MailMessage Msg = new MailMessage(); Msg.To.Add(new MailAddress(ToPerson));Msg.From = new MailAddress(FromPerson); Msg.Subject = Subject; Msg.Body = BodyText;Msg.BodyEncoding = System.Text.Encoding.UTF8; Msg.SubjectEncoding = System.Text.Encoding.UTF8;Msg.Attachments.Add(new Attachment(FileName)); SmtpClient Client = new SmtpClient("127.0.0.1");Client.Send(Msg); I get  the exceptions: Unable to send email Unable to connect to remote server  What should I be specifying as the remote server for the smtp c...

For interrupting.web form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form
Web Form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form ! Because of my pool English, if you can't see , I will explain more ! ThanksGambler is the real life I guess you mean when form grows it also grow parent div element. This is normal. If you want div to stay fixed size and rather clip the form and maybe show a scrollbar, look at overflow property in CSS.Thanks------------------------------------------------------------This posting is provided "AS IS" with no warranties, and confers no ...

Include web form inside web form
I tried to include an aspx file in a asp.net web form. However, all the web controls (textbox, button) in the included page are not displayed when called. <Form id="Form1" method="post" runat="server"> <%   Response.writeFile("subPage.aspx"); %> <asp:button id="btnPrev" runat="server" text="Previous"></asp:button> </Form> There are some <asp:textbox> controls in the subPage.aspx file, the file itself works fine, but when it is included in the main page, all the controls are not displayed. Please assist. Thanks   u should u...

Web Form vs. Web Content Form
If you don't mind, I would like to know what is the difference between those two items, when I go to add a new item I see both of those and I don't know what the difference is.  A content form is for use with a masterpage. A web form is a standalone web page. If you select web content form, you will then have to specify a masterpage for it. and what is a master page used for?  Hi, a master page is used to give a constant look and theme to a site, without having to duplicate code. So basically you can put your header, menu, nav and footer on a master page. Then a...

Web Form embedded in another Web Form
Hi,  I have programmed a Web Form which acts like a scientific calculator. I would like to embedd this calculator in the upper left hand corner of another accounting Web Form. I don't want to host the calculator on the same server as the accounting page. I.e. I want them to have distinct URLs. Classically, I would do this using frames, but is there a better way using ASP? Is there some sort of Panel which can display the webpage at a specific URL which I can just drag onto my accounting Web Form? Thanks,  P1000   Frames are the only way to embed a webform inside ano...

How to fire events in other web form from other web form ?
Suppose that I have A and B web form. I want to trigger B web form's Page_Load event from A web form. How can I do that ? Thanks in advanced WilbertWilbert Bujn Create a public method in B that call the load method : public void Load(object sender, System.EventArgs e) { Page_Load(sender, e) ; } In the page_load of A, instanciate a B object and then call the function B myB = new B() ; myB.Load() ; Quicky Thank you quicky, it works fine. WilbertWilbert Bujn...

calling a web form from another web form
I would like to know what is the best way to open a web form from another web form. I would like to call it from a button control. Thanks Well, if I've grasped your question right, there are many methods to do that: 1)Response.Redirect > To navigate to another page from code and is equal to clicking a hyperlink. I suggest this as I think it's closer to your question. 2)Server.Transfer > This ends the current web form and begins a new web form. It's usable when you want to pass some variables i.e (Label1.Text) to the next immediate page. It's not safe though and not used to send p...

Implementing .Net Form into an APS.net 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 ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

How to access a control on a web form from anoter web form
hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it possible to access lbl1 from form2, change its text permenantly? thanks.   refer: http://dotnetslackers.com/Community/blogs/haissam/archive/2007/11/26/ways-to-pass-data-between-webforms.aspxSSNPlease remember to click "Mark as Answer" on the post that helps you. MinaSamy: hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it p...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

Web resources about - Trying to send an email from a web form - asp.net.web-forms

Bill Cosby's Lawyer Releases Statement After Arraignment
Bill Cosby ‘s attorney is speaking out after he plead not guilty to sexual assault charges in the 2004 Andrea Constand case. The 78-year-old ...

Brussels Police Confirm Investigation into Terror Orgy Reports
On Wednesday, the New York Times reports , police officials in Brussels confirmed that they had begun an investigation into earlier reports of ...

Texas 'affluenza' teen is fighting deportation from Mexico
Los Angeles Times Texas 'affluenza' teen is fighting deportation from Mexico Los Angeles Times The Texas teenager who became infamous for ...

Steam Confirms 34k User Details Revealed In DoS
Valve had stepped forward to provide an explanation concerning the Christmas Day snafu , where it involved Steam users being greeted by information ...

Apple agrees to pay £234m to settle Italian tax dispute - Business - The Guardian
Corporation tax deal follows Apple Italia’s alleged failure to declare earnings in Italy but settlement is thought to be one-third of the estimated ...

Mayor of Chicago Announces Measures to Curb Use of Deadly Force by the Police
New York Times Mayor of Chicago Announces Measures to Curb Use of Deadly Force by the Police New York Times CHICAGO — Under intense pressure ...

New Year’s Eve: Netflix Creates Fake Countdowns To Help Put Kids To Bed Early, Parents Rejoice
On New Year’s Eve, parents of young children are always faced with the difficult question: Let the little ones stay up late and deal with the ...

Facebook Free Basics controversy in India: Here’s all you need to know
With Facebook defending Free Basics all out, we take a look at the latest Net Neutrality debate that has played out in India.

Try to resist photos of President Obama designed to melt your cold heart
Chief official White House photographer Pete Souza has collected his favorite images of the year, either taken by himself or a member of his ...

U.S. preparing fresh sanctions on Iran: WSJ
(Reuters) - The Obama administration is preparing to sanction nearly a dozen companies and individuals in Iran, Hong Kong and the United Arab ...

Resources last updated: 12/31/2015 4:07:26 AM