andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 169 forks source link

Html Helpers not working from console application #165

Open VickyMahir opened 7 years ago

VickyMahir commented 7 years ago

Hi,

I have one console application and one mvc web application. That two application use one common class library to send mail using postal. From web its working send email with html embedding image but in console application its not working. I have do as per below

Class Library Project : PostalEmailSenderService.cs File

public bool FromWebEmail()
{
              var email = new ExampleEmail
                {
                    Subject = "Welcome Mail",
                    To = "test@test.com",
                    From = "test@test.com"
                };
               email.Send();
              return true;
}

public bool FromConsoleEmail()
{
               var viewsPath = Path.GetFullPath(@"..\MyWebApplicationDirectory\Views\Emails");
                var engines = new ViewEngineCollection();
                engines.Add(new FileSystemRazorViewEngine(viewsPath));
                EmailService service = new EmailService(engines);

              var email = new ExampleEmail
                {
                    Subject = "Welcome Mail",
                    To = "test@test.com",
                    From = "test@test.com"
                };
              service.Send(email);
              return true;
}

Web Application Project :

PostalEmailSenderService ps = new PostalEmailSenderService(true);
ps.FromWebEmail();

Console Application Project :

PostalEmailSenderService ps = new PostalEmailSenderService(true);
service.RegistrationEmail();

Emails\Example.cshtml - This file is in my web application.

To:@Model.To
Subject:@Model.Subject

I am just test my email from web and console aplication
@Html.EmbedImage("~/Content/IMGMail.jpg")

Web application and Console Application use Same View is in Web Application.

So please tell me how to do this ?

Thanks

austindenz412 commented 12 months ago

Hi,

It seems like the issue lies in integrating Postal for sending emails in a console application. In your console application, ensure that the path to your view in 'FileSystemRazorViewEngine' is correct and Best Golf accessible. Additionally, confirm that the required dependencies and configurations for Postal are properly set up in the console application.

Best regards.

christhomas412 commented 12 months ago

Hi, It seems like you're encountering an issue where sending emails with embedded images works in the MVC web application but not in the console application. To troubleshoot this, ensure the correct path to the view is specified and the image is properly embedded in the console application. Check if the Apk path to the image is accessible in the console application and adjust accordingly. Also, make sure the ExampleEmail class and its usage are consistent in both applications. Double-check the registration of the email service and any configurations specific to the console application.

jhoncarles725 commented 6 months ago

Have you checked if the console application has access to necessary resources, such as the tyre pressure image files, and if there are any differences in how Postal is configured between the two applications? That could help pinpoint the issue.

jackjhones12 commented 3 months ago

Had the same issue! Switching to a web context explore fixed it for me. Anyone found a console-specific workaround.