Can MvcMailer be used in a class library? - c#

I want to use MvcMailer in a class library, which would essentially be my one-stop-shop for composing and sending emails for my solution. I thought that that is what MvcMailer was designed for, but it appears it cannot find any of my .cshtml files--I guess it expects them to in my startup project.
Is there any way for MvcMailer to be 100% separate from my other projects?
Thanks.

This is not possible according to MvcMailer documentation https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide (extract below), maybe you can have a separate web project that its only purpose is to send emails and only accept requests from your application
Email Sending from a Background Process
Do you need to send emails from a background process? Yes, you're right. You don't want to block your request/response cycle for that notification email to be sent. Instead, what you want is a background process that does it for you, even if it's sent after a short delay. Here's what you can do:
Save your email related data into a database.
Create a REST/SOAP web service that sends out the emails. This will ensure your Mailer has access to the HttpContext, which is essential for the core ASP.NET MVC framework to work properly. For example, to find your views, produce URLs, and perform authentication/authorization.
Create a simple App that calls the web service. This could be a windows service app or an executable app running under Windows Scheduled task.
A future version of MvcMailer is likely to have support for this. But it is hard because of two reasons:
MailMessage is not Serializable out of the box and has a lot of complex fields and associations.
The core ASP.NET framework still needs HttpContext :(

Related

How do i broadcast a message to all clients via Web API

I have two Projects, an Asp.net WebAPI & a separate Single Page Web Application. My requirement is that when a form is submitted via the web application it is processed at the Web API. Once the Request has been handled successfully i want to broadcast a message to all the clients notifying them that a new request had been submitted.
How can I do it? Any help would be appreciated.
I looked into SignalR, but couldn't find an implementation for this requirement.
Pusher's got libraries you can use to handle anything notifications https://pusher.com/docs/libraries
I suggest you use signalR to cater your requirement. You can go thru this link https://learn.microsoft.com/en-us/aspnet/signalr/overview/getting-started/ for more details.
If your project is small use pusher "https://pusher.com/"
when you use that well It may be cheaper than you make And less resources.

What kind of ASP.NET Web Site project i should choose?

I want to build a web application using Azure.
The service will be call MessagingService.
The service need also use Twilio rest to execute automated voice messages.
The service will have one client that will send him HTTP post data request.
The service will need to translate that request to messages and make an out-bounded calls using Twilio rest. I need that my service will have a domain name because that what Twilio demand to use there service. I want also that the service can perform auto scaling. At first I want to build this app using ASP.NET MVC but I cannot see the need of using view at my service because it is just needed to do some background tasks so i don't now how to build it because MVC is model view controller and I dont need view for this? My limitation is that I need it will have a domain that I can use Twilio. Thanks.
sounds to me you want a WEB api v2. With the build-in publish method from VS, you can easily publish to azure, or choose for CI/CD with Jenkins for example. With azure you can handle the scale out (more instances) or scale up (more resources). This has no impact for you choice of API.
Have you looked at .NET core? You have a lot of standard built-in function with DI etc.

Building a remote command for Elpis in C# through HTTP API

I am helping to build Elpis, which is an open source pandora music player, built with C# and WPF.
Now what i want is to add an HTTP API so that the user may control the program through a browser, like play/pause, like/dislike the current song.
The point afterwards is to control the program through a mobile device accessing the HTTP API.
How exactly should i build the HTTP API so that it can control it?
Github for the project: https://github.com/adammhaile/Elpis
Without knowing why exactly you want the user to control a GUI application via the browser, it's hard to give you good advise.
Assuming you are running your GUI on Windows, take a look at OWIN and the project Katana. They allow you to easily host HTTP interfaces in your own application.
It may be overkill for your project but I would suggest using ASP.NET Web API so that you can build backend web services.
The easiest way to do what you want, assuming you really want to "control the GUI remotely" is to just install TeamViewer on your PC and on your mobile device. Then you could remote in and completely control your GUI.
But I what I think you're after is something more like Google Music. Where you can stream your music through the Internet and onto your mobile devices. If this is the case, I recommend you look at the ASP.NET Web API.
It's not hard to build a web server in C#. You can embed it into your application, and expose parts of your application to HTTP endpoints as an API. You can use the HttpListener class which is part of .NET, and do everything from the ground up yourself. Or you could use something like Nancy, which is a lightweight framework that provides a lot of useful scaffolding like URL routing.
Ended up using Kayak(https://github.com/kayak/kayak) for my self-hosted API.
The example of integration can be seen here:
https://github.com/adammhaile/Elpis/blob/master/Elpis/WebInterface.cs

Integrate an E-Mail server into ASP.NET

I've a general design question:
I have a mailserver, written in C#.
Then I have a web forum software, written in for ASP.NET in C#.
Now I'd like to integrate the mailserver into the ASP.NET forum application.
For example, I'd like to make it possible that one can create a mailinglist from the forum, and give users the oportunity to add oneselfs to the mailinglist members in the forum, and then add the new list-members to the respective mailinglist on the server.
Since the server is a separate console/winforms/service application, I first thought I'd best use .NET remoting for this.
But my second thought was, that some users might host their forum on a host where
(a) they don't have a virtual machine where they can do what they want
(b) the admin of the host might not want to install an additional mailserver or charge extra for this
(c) the user might have a service plan that only permits to add a web-application, not external programs (very likely)
Now, I wanted to ask:
Is it possible to fully integrate a mailserver into an ASP.NET application somehow ?
(I have the full source of the server + ASP.NET application)
Well, it probably won't be a page or a ashx handler, but something like a http module ?
Or what's the general way to integrate TCP/IP applications into asp.net ?
(Of course I'm assuming the respecive ports are available/forwarded - and I'll make it possible to also run it with the e-mail server as external application)
In the ideal case I'd do the following:
Set it up on your own server(s) and expose a WCF/web service that your web app will/can interact with.
If you can't or don't want to afford to keep it running on your own, you could then charge a subscription fee for it.
It's probably not a very great idea, but you can start a thread in Global.asax and do background processing while the application pool is running/the web app is not reloaded. So you could start your server there, but you have no control over the lifetime of it
Adding to chris166's comment... you also wouldn't get control over when the application is started. [Since the application won't be loaded until a page is requested...] Its probably a better idea to setup some sort of integration between the web app and the console/service app.
I'd probably tend towards setting up a near-realtime integration where the mailserver polls the forum app for requested changes.

View need to go Winform to Webform, what is your advices?

Our application is well structured (well we did our best!) and we have split the Model from the View, Now, we need to let some information to our client with a web access. We would like to build something small with IIS and some webform.
Here some information you might think are useful:
Our controller have Thread of database queries
Our database is PostGresql
All is build with C#2.0
We used a lot of databinding between our View and Controller in Winform.
Winform will stay for internal purpose, only a small part will be available on the Internet.
What are your suggestions for this kind of move?
Update
We will host the web in our company server so the database will stay inside the business. No need to duplicate data or any synchronization.
I think the "synchronizing" Michael is talking about is the data in the database and the view presented by the Winform app.
We had a similar problem, and the solution we came up with is to create a Web service that exposes the data via XML and use the service from both the web app and Winform app. Every time you update data send it to the web service, and every time you perform a query get the latest data from the service. Do not consider caching data on the Winform app unless you have profile data showing it is a bottleneck, or you want to run unconnected from the network.
This is perfectly possible in .Net 2, you do not need 3.0 or WCF.
The biggest challenge is going to be synchronizing your database between the local Winforms application and the hosted Webforms application. Once you do that, creating the web app is easy.
If your web application is read only, then you can set up replication. Find a tool that you like. Three that I found through a quick search are:
Slony-I
Mamoth Replicator
Bucardo
If your web application is not read only, then the problem is more difficult. You might want to consider upgrading to .NET 3.0 or 3.5 so you can use WCF. If there is a significant overlap in functionality, you might want to move your data to the web exclusively and expose it through WCF services.

Categories