locked
MVC Send Mail Help RRS feed

  • Question

  • User-507786106 posted

    I need to send mail using MVC, can someone give me some help with setting up a send mail in my codes, please. Start with basic ... thanks

    Tuesday, June 18, 2019 2:53 PM

Answers

  • User1520731567 posted

    Hi slimbunny,

    slimbunny

    I need to send mail using MVC, can someone give me some help with setting up a send mail in my codes, please. Start with basic

    You could refer to this article,about send email by MailMessage and SmtpClient,it covered the basics of sending email from and ASP.NET MVC site and the most common error messages encountered when sending email programmatically.

    Also,you could refer to this article about send email by WebMail,The WebMail helper makes it easy for you to send email.

    They all need to via SMTP or via any number of free services such as Google's Gmail system, Microsoft's Outlook.com/Live service,.

    It can be a challenge sometimes to make sure you have the right settings for the SMTP server, port number, and so on. Here are a few tips:

    • The SMTP server name is often something like smtp.provider.com or smtp.provider.net. However, if you publish your site to a hosting provider, the SMTP server name at that point might be localhost. This is because after you've published and your site is running on the provider's server, the email server might be local from the perspective of your application. This change in server names might mean you have to change the SMTP server name as part of your publishing process.
    • The port number is usually 25. However, some providers require you to use port 587 or some other port.
    • Make sure that you use the right credentials. If you've published your site to a hosting provider, use the credentials that the provider has specifically indicated are for email. These might be different from the credentials you use to publish.
    • Sometimes you don't need credentials at all. If you're sending email using your personal ISP, your email provider might already know your credentials. After you publish, you might need to use different credentials than when you test on your local computer.
    • If your email provider uses encryption, you have to set WebMail.EnableSsl to true.

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 19, 2019 2:31 AM

All replies

  • User753101303 posted

    Hi,

    See for example https://docs.microsoft.com/en-us/dotnet/api/system.web.mail.smtpmail?view=netframework-4.8 (ie define From, To, Subject & Body).

    You can use https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/smtp-element-network-settings#example to configure mail settings which are automatically used by the SmtpClient class.

    More likely it won't work the first time and we would need the EXACT error message (ie exception.ToString()) so that we can tell you which problem you have.

    Tuesday, June 18, 2019 3:01 PM
  • User1520731567 posted

    Hi slimbunny,

    slimbunny

    I need to send mail using MVC, can someone give me some help with setting up a send mail in my codes, please. Start with basic

    You could refer to this article,about send email by MailMessage and SmtpClient,it covered the basics of sending email from and ASP.NET MVC site and the most common error messages encountered when sending email programmatically.

    Also,you could refer to this article about send email by WebMail,The WebMail helper makes it easy for you to send email.

    They all need to via SMTP or via any number of free services such as Google's Gmail system, Microsoft's Outlook.com/Live service,.

    It can be a challenge sometimes to make sure you have the right settings for the SMTP server, port number, and so on. Here are a few tips:

    • The SMTP server name is often something like smtp.provider.com or smtp.provider.net. However, if you publish your site to a hosting provider, the SMTP server name at that point might be localhost. This is because after you've published and your site is running on the provider's server, the email server might be local from the perspective of your application. This change in server names might mean you have to change the SMTP server name as part of your publishing process.
    • The port number is usually 25. However, some providers require you to use port 587 or some other port.
    • Make sure that you use the right credentials. If you've published your site to a hosting provider, use the credentials that the provider has specifically indicated are for email. These might be different from the credentials you use to publish.
    • Sometimes you don't need credentials at all. If you're sending email using your personal ISP, your email provider might already know your credentials. After you publish, you might need to use different credentials than when you test on your local computer.
    • If your email provider uses encryption, you have to set WebMail.EnableSsl to true.

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 19, 2019 2:31 AM