Advertisement

07.06.2008 at 01:16AM PDT, ID: 23541409
[x]
Attachment Details

How to show a "From" field from a contact us form while using gmail smpt host with credentials setup in web.config file?

Asked by ubaidx in Programming for ASP.NET, .NET, Simple Mail Transfer Protocol (SMTP)

Tags: ASP.NET C#, C#

I am trying to setup a contact us form using gmail as my smtp host, I have my username and password setup in my web.config file. When I  enter a specific email address in the "From" field of the form, it doesnt show up in my inbox. Rather, My email address is showed up as both sender and reciever. Can somebody help?  I understand that smtp.gmail.com needs to authenticate me form my userid and password (setup in web.config), but it shouldn't display my email address as the sender. While in debugging mode, I could see the value of the "From" fiield is passed to the Mail Message constructor, But in the end I see my email address as the sender.  Is there any way that this could not happen? If not then what is the best way of setting up contact us forms? how they are done in real world apps?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
C# file:
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string from = txtEmail.Text;
        string body = txtComments.Text;
        MailMessage msg = new MailMessage(from, "ubaidx@gmail.com", "Customer Feedback", body);
        SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 25);
         mailClient.EnableSsl = true;
        mailClient.Send(msg);
        msg.Dispose();
        Response.Write("Message has been sent");
    }
 
Web.config file:
 
<configuration>
<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com" port="25" userName="ubaidx" password=""/>
        </smtp>
         </mailSettings>
          </system.net>
</configuration>
 
Loading Advertisement...
 
[+][-]07.06.2008 at 04:45AM PDT, ID: 21939956

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, .NET, Simple Mail Transfer Protocol (SMTP)
Tags: ASP.NET C#, C#
Sign Up Now!
Solution Provided By: naspinski
Participating Experts: 2
Solution Grade: B
 
 
[+][-]07.06.2008 at 12:27PM PDT, ID: 21941342

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.06.2008 at 02:59PM PDT, ID: 21941771

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.06.2008 at 07:27PM PDT, ID: 21942473

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628