JuergenGutsch / blog

Personal blog about web development based on .NET and .NET Core
https://asp.net-hacker.rocks/
Other
31 stars 17 forks source link

Creating an email form with ASP.NET Core Razor Pages #83

Open JuergenGutsch opened 5 years ago

JuergenGutsch commented 5 years ago

Written on 26.07.2017 07:55:13

URL: http://asp.net-hacker.rocks/2017/07/26/razor-pages-email-form.html

JuergenGutsch commented 5 years ago

Comment written by Nick G. on 18.10.2017 18:40:26

Very interesting stuff the Razor pages. I personally prefer the MVC three separate folders but I can see how it can help with small projects.

Thanks for the article!

JuergenGutsch commented 5 years ago

Comment written by Jürgen Gutsch on 19.10.2017 16:48:17

Thanks for reading :)

JuergenGutsch commented 5 years ago

Comment written by tha on 23.10.2017 17:11:30

can you post how the full end code look like?

JuergenGutsch commented 5 years ago

Comment written by Rob on 23.12.2017 21:48:16

Novice Question: Where do the last two code blocks go. Thanks for the Article

JuergenGutsch commented 5 years ago

Comment written by Jürgen Gutsch on 16.01.2018 17:09:40

Glad you like it :-)
Depends where you wanna place the code to send the mails. Could be a separate email service class or directly in the OnPostAsync method where I put the comment ("// create and send the mail here") in

JuergenGutsch commented 5 years ago

Comment written by Jürgen Gutsch on 16.01.2018 17:10:19

Please see Robs comment

JuergenGutsch commented 5 years ago

Comment written by VerdenDev on 26.01.2018 14:11:19

Hi Jürgen,

First time using this site, great article! Coincidentally I think I've also seen some of your answers on StackOverflow before.

Thank you for a great article!

JuergenGutsch commented 5 years ago

Comment written by viven on 24.02.2018 15:16:57

What about Robs comments?

JuergenGutsch commented 5 years ago

Comment written by Jürgen Gutsch on 26.02.2018 08:14:53

:-D I mean my reply on robs comment on this post

JuergenGutsch commented 5 years ago

Comment written by Craig Nicholas on 07.03.2018 10:32:43

Hi Jürgen,
Where is ContactModel defined?

JuergenGutsch commented 5 years ago

Comment written by Jürgen Gutsch on 07.03.2018 16:07:35

Hi Craig,
Many thanks for the comment.
The ContactModel ist the "code behind" class of the contact cshtml Razor page. Every Razor page has a model class in behind that has the same name as the page and the prefix "Model".
Sorry for the confusion. I expected it to be clear, because this is how Razor pages work.

JuergenGutsch commented 5 years ago

Comment written by Craig Nicholas on 07.03.2018 16:25:51

Thank you. I don't normally use code-behind so was not sure. Based on your example I have a working test project.

FaridGN commented 3 years ago

Does it work for gmail, yahoo too? Can someone send message to my gmail account if I use this method?

JuergenGutsch commented 3 years ago

Hi @FaridGN

Yes, just configure the line with: message.To.Add(new MailAddress("me@mydomain.com")); Add your email address here.

If you want to use Gmail, Yahoo, etc. as SMTP, you should configure the SmtpClient: var smtpClient = new SmtpClient("mail.mydomain.com")