Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 19th, 2010, 01:54 PM
Authorized User
 
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending Email

I have configured my web.config like this
Code:
 
<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network enableSsl="true" host="smtp.gmail.com" password="mypassword" userName="myemail@gmail.com" port="587"/>
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
and in the page load of the demo page i have put the following:
Code:
 MailMessage mymessage = new MailMessage();
        mymessage.Subject = "You have new msg";
        mymessage.Body = "hello from planet wrox";
        mymessage.From = new MailAddress("ABC@hotmail.com", "hehe!");
        mymessage.To.Add(new MailAddress("DestinationEmail@hotmail.com", "Reciever Name!"));
        SmtpClient smtp = new SmtpClient();
        smtp.Send(mymessage);
the email gets sent from the email configured in the web.config, isn't it supposed to be sent from the email indentified in the mymessage.from code? and when i commented the mymessage.from line, i got an error, so why do we use it if it won't appear in the email?
Reply With Quote
  #2 (permalink)  
Old September 19th, 2010, 02:13 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Nope. The e-mail address you are referring to is "just" your user name to authenticate with the SMTP server.

But you can specify the from address in the "from" attribute as shown in the book. Once you do that, you can leave out the From from your code.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old September 19th, 2010, 02:16 PM
Authorized User
 
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but when i specify the from address, the email shows the from is the email used in web.config????
Reply With Quote
  #4 (permalink)  
Old September 19th, 2010, 02:55 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Isn't that exactly what you're after?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old September 19th, 2010, 03:03 PM
Authorized User
 
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the email in the web.config for authenticating me to send emails am I right? so i use google smtp in order to send emails, first question can I use like hotmail smtp and use a hotmail Email to authenticate? my other question is I don't want my email which I use to authenticate to appear in the From title, then what's the point of defining a from email called me@mydomain.com which is not going to appear in the emails? I want to authenticate using an email and showing a from address using an alias.

in web.config >> my real email address
however to show from>> alias email address.
Reply With Quote
  #6 (permalink)  
Old September 19th, 2010, 03:20 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Have you tried the from attribute on the smtp element in the web.config and specify the address you want to show in the From field in the mail? That's what it's for. You can override that default through code by setting the From property.

Some mail servers overrule the from address, BTW. So even though you set an explicit address in the from attribute in web.config, you still end up with the e-mail address associated with the account ou're uisng.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old September 19th, 2010, 03:24 PM
Authorized User
 
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes i have tried it in the web.config also, but same result, it shows the authentication account as the from address.
Reply With Quote
  #8 (permalink)  
Old September 19th, 2010, 03:38 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

In that case, I think your SMTP server is overruling the address, probably for security reasons.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #9 (permalink)  
Old September 19th, 2010, 04:45 PM
Authorized User
 
Join Date: Sep 2010
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

by smtp server you mean here smtp.gmail right? is there any other smtp I can use?
Reply With Quote
  #10 (permalink)  
Old September 19th, 2010, 05:29 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

If you have an hotmail account you can use that one as well. Alternatively, your ISP / network provider may offer one....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending email Sheraz Khan Classic ASP Basics 1 December 12th, 2009 12:58 AM
Sending Email drjohnnygills BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 August 13th, 2009 05:09 AM
Need Help in sending email khalidj06 Forum and Wrox.com Feedback 6 April 14th, 2006 08:16 AM
email sending msrnivas .NET Web Services 6 June 26th, 2004 06:59 AM



All times are GMT -4. The time now is 11:45 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.