Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Email Sending From FrontEnd Pages #3351


User avatar
0
avanekar02 created

Hello

Can you show me how i can send email from a FrontEnd page using EmailSender.

Thanks

Anwar


6 Answer(s)
  • User Avatar
    0
    avanekar02 created

    Can you please check help me out here i need to send email from front end pages

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @avanekar02,

    You just need to do it like we do for admin site. Have you tried it ?

    Thanks.

  • User Avatar
    0
    avanekar02 created

    can you pint me to a page, please

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You just need to inject IEmailSender to your controller and send email using it. You can check UserEmailer for it's usage.

    Thanks.

  • User Avatar
    0
    avanekar02 created

    this is the error i get

    HTTP Error 400.0 - Empty or invalid anti forgery header token. shown below is cshtml and controller file

    This is my form feedback.cshtml

    @using Samit.CmsProTest.Web.Navigation

    @{ ViewBag.CurrentPageName = PageNames.Frontend.FeedBack; }

    <div class="row"> <div class="col-md-12 page-404"> <div class="number font-red"> @L("FeedBack") </div> <div class="details" style="width:40%"> <form class="feedback-form" action="@Url.Action("FeedBack")" method="post">

                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;label class=&quot;control-label visible-ie8 visible-ie9&quot;&gt;@L("Name")&lt;/label&gt;
                    &lt;input class=&quot;form-control placeholder-no-fix&quot; type=&quot;text&quot; placeholder=&quot;@L(&quot;Name&quot;)&quot; name=&quot;Name&quot; required value=&quot;@Model.Name&quot; maxlength=&quot;@Samit.CmsProTest.Authorization.Users.User.MaxNameLength&quot; /&gt;
                &lt;/div&gt;
                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;label class=&quot;control-label visible-ie8 visible-ie9&quot;&gt;@L("EmailAddress")&lt;/label&gt;
                    &lt;input class=&quot;form-control placeholder-no-fix&quot; type=&quot;email&quot; placeholder=&quot;@L(&quot;EmailAddress&quot;)&quot; name=&quot;EmailAddress&quot; required value=&quot;@Model.EmailAddress&quot; maxlength=&quot;@Samit.CmsProTest.Authorization.Users.User.MaxEmailAddressLength&quot; /&gt;
                &lt;/div&gt;
                &lt;div class=&quot;form-group &quot;&gt;
                    &lt;label class=&quot;control-label visible-ie8 visible-ie9&quot;&gt;@L("FeedBack")&lt;/label&gt;
                    &lt;textarea class=&quot;form-control&quot; rows=&quot;5&quot; placeholder=&quot;@L(&quot;FeedBack&quot;)&quot; name=&quot;Suggestions&quot; required value=&quot;@Model.Suggestions&quot;&gt;&lt;/textarea&gt;
                &lt;/div&gt;
                &lt;div class=&quot;form-actions&quot;&gt;
                 
                    &lt;a href=&quot;@Url.Action(&quot;Index&quot;, &quot;FeedBack&quot;)&quot;&gt;     &lt;/a&gt;
                    &lt;button type=&quot;submit&quot; class=&quot;btn btn-success uppercase pull-right&quot;&gt;@L("Submit")&lt;/button&gt;
                &lt;/div&gt;
            &lt;/form&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    

    </div>


    FeedBackController

    using Abp.Domain.Uow; using Samit.CmsProTest.School.Courses; using Samit.CmsProTest.School.Courses.Dto; using Samit.CmsProTest.Web.Models; using Samit.CmsProTest.Web.Models.FeedBack; using System.Web.Mvc;

    namespace Samit.CmsProTest.Web.Controllers { public class FeedBackController : CmsProTestControllerBase { private readonly ICourseDtlAppService _courseDtlAppService;

        public FeedBackController(ICourseDtlAppService courseDtlAppService)
        {
            _courseDtlAppService = courseDtlAppService;
        }
    
        public ActionResult Index(FeedBackViewModel feedbackViewModel)
        {
    
            var model = new FeedBackViewModel();
    
            return View(model);
        }
    
        [HttpPost]
        [UnitOfWork]
        public ActionResult FeedBack(FeedBackViewModel feedBackModel)
        {
            var model = new FeedBackViewModel();
    
            return View(model);
        }
    
    
    }
    

    }

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can do two things.

    1. Disable anti forgery token validation by adding [DisableAbpAntiForgeryTokenValidation] attribute to your action.
    2. add below line to your frontend razor view
    @{
        SetAntiForgeryCookie();
    }
    

    Thanks.