blog icon indicating copy to clipboard operation
blog copied to clipboard

Creating an email form with ASP.NET Core Razor Pages

Open JuergenGutsch opened this issue 6 years ago • 14 comments

Written on 26.07.2017 07:55:13

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

JuergenGutsch avatar Nov 16 '18 21:11 JuergenGutsch

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 avatar Nov 16 '18 21:11 JuergenGutsch

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

Thanks for reading :)

JuergenGutsch avatar Nov 16 '18 21:11 JuergenGutsch

Comment written by tha on 23.10.2017 17:11:30

can you post how the full end code look like?

JuergenGutsch avatar Nov 16 '18 21:11 JuergenGutsch

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 avatar Nov 16 '18 21:11 JuergenGutsch

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 avatar Nov 16 '18 21:11 JuergenGutsch

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

Please see Robs comment

JuergenGutsch avatar Nov 16 '18 21:11 JuergenGutsch

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 avatar Nov 16 '18 21:11 JuergenGutsch

Comment written by viven on 24.02.2018 15:16:57

What about Robs comments?

JuergenGutsch avatar Nov 16 '18 21:11 JuergenGutsch

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 avatar Nov 16 '18 21:11 JuergenGutsch

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

Hi Jürgen,
Where is ContactModel defined?

JuergenGutsch avatar Nov 16 '18 21:11 JuergenGutsch

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 avatar Nov 16 '18 21:11 JuergenGutsch

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.

JuergenGutsch avatar Nov 16 '18 21:11 JuergenGutsch

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

FaridGN avatar Feb 05 '21 20:02 FaridGN

Hi @FaridGN

Yes, just configure the line with: message.To.Add(new MailAddress("[email protected]")); 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")

JuergenGutsch avatar Feb 12 '21 08:02 JuergenGutsch