• 0

VB.Net service to send xml email from MSMQ


Question

I have created a MSMQ server and written VB.NET code to drop an XML file into a private queue in the following format:

<emailRequest>

<senderName>Tester</senderName>

<senderAddr>sender@thedomain.com</senderAddr>

<subject>Test Subject</subject>

<body>This is a test</body>

<recipients>receiver@domain.com</recipients>

</emailRequest>

I need some guidance on creating a VB.NET windows service that checks the private queue for messages, processes them out sends them out via our SMTP server. I've had a good look around the Internet but can't find a definitive guide. Can you point me in the right direction, or even provide some code examples?

6 answers to this question

Recommended Posts

  • 0

Have a look at NServiceBus - http://www.nservicebus.com/

We use this, pain in the ass to debug but will do what you need MSMQ wise but without having to interact with the MSMQ, NSB does it all for you.

GE

  • 0

We use MSMQ together with C# to do something similar. I've never used NServiceBus, but it sounds a bit complicated for what you're trying to do.

Writing my own handler for writing and reading for the MSMQ took about 100 lines of code. The handler will fetch an item from the queue send it for processing.

Since my code is C# I won't share it, but there's some basic useage info using Visual Basic on this page: http://www.microsoft.com/msj/0599/msmq/msmq.aspx

Hope that helps you out.

  • 0

I don't know MSMQ, but since you've written the code to put the XML message into the queue, you should be able to write the code to get it out and process it.

Once you have your batch of XML messages, you will want to loop through them and use the System.Net.Mail.SmtpClient class to do the actual heavy lifting.

Here is a snippet from MSDN:

Public Shared Sub CreateTestMessage2(ByVal server As String)

Dim [to] As String = "jane@contoso.com"

Dim [from] As String = "ben@contoso.com"

Dim message As New MailMessage([from], [to])

message.Subject = "Using the new SMTP client."

message.Body = "Using this new feature, you can send an e-mail message from an application very easily."

Dim client As New SmtpClient(server)

' Credentials are necessary if the server requires the client

' to authenticate before it will send e-mail on the client's behalf.

client.UseDefaultCredentials = True

Try

client.Send(message)

Catch ex As Exception

Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString())

End Try

End Sub

I imagine you would call this Sub from inside your loop.

Question, with MSMQ can you queue up objects or is it limited to XML? If it can handle objects, maybe adding MailMessage objects directly into the queue might make the service a bit simpler. You would then only have to pull out all the MailMessage objects and fire them at .Send() method. Either way, you are going to have to create MailMessage objects on one side of MSMQ.

  • 0

With MSMQ you can queue anything as long as you know how you serialized it. You can even put objects of different types into the same queue, and the queue also has a priority system you can take advantage of (urgent mails can get high pri and will be withdrawn from the queue before other mail).

If more than one program will access the queue, raw objects are perhaps not the best way to go. You'll be better off with XML then, since the job of actually setting up the Message for sending is not the hard part of this program.

This topic is now closed to further replies.
  • Posts

    • Console game sales still make more money than PC game sales. Both behind mobile game sales. Both Microsoft and Sony are making big money off of the games Microsoft is porting to PS. Those 75 million PS5’s are making an impact. There is a big market for console gaming and only Xbox console sales have suffered. The PS5 is on track to out sell the PS4. Yes Sony is porting their games to PC 18 months on average after they hit the PS5. Most console gamers want nothing to do with PC gaming especially Windows 11.
    • Oooh so that’s why. I was about to say there’s zero financial incentive to stop releasing songs for an EXISTING platform, but now I understand. Pathetic. I was planning on buying this game for VR2, but I guess I’ll just stick with Synth Riders then.
    • WD SSDs still block Windows 11 24H2 download and installs, Microsoft may be guilty too by Sayan Sen Microsoft has been slowly lifting several upgrade blocks for Windows 11 version 24H2, the 2024 feature update for Windows 11. For example, the most recent one was related to browser compatibility, and it was removed last month. This safeguard hold was lifted about a week after the company released the update such that it was available for download to everyone. However, there are still plenty of other compatibility blocks that are still in place. These include ones for Dirac Audio, sprotect SYS driver conflict, among others. Meanwhile, it looks like there is also an upgrade block on certain Western Digital SSDs that prevents them from getting the feature update. While Microsoft, or at least Windows 11, seems to be blocking the upgrade, the issue is not documented on the tech giant's health dashboard website alongside the other entries. The typical "What needs your attention" message box pops up indicating that the WD NMVe SSD in the user's system is the issue. It says: Thus, Windows thinks the WD drive in question is not compatible with the Windows 11 2024 update. As it turns out, the problem, one related to Host Memory Buffer (HMB), has seemingly already been fixed back in October 2024 with a new firmware update. However, Windows does not seem to deliver the correct link to download the update, which means users may still be unable to download Windows 11 24H2 on their PCs. A Reddit user found out that they were able to bypass the block by manually downloading the firmware from the SanDisk official support page for the corresponding drive model. They write: Thus, in case you happen to own such a disk, make sure to head over to the SanDisk Dashboard website here. It provides support for the following models: WD Green, Blue, Red, WD_BLACK, SanDisk SSD PLUS M.2, Extreme M.2, Extreme Pro M.2, Ultra 3D. You can find the instructions for updating firmware at this link. Source: Microsoft forum (link1, link2), Reddit
  • Recent Achievements

    • Week One Done
      Higante88 earned a badge
      Week One Done
    • Conversation Starter
      CarloDuplessis earned a badge
      Conversation Starter
    • First Post
      hhgygy earned a badge
      First Post
    • Collaborator
      WiltshireHam went up a rank
      Collaborator
    • One Month Later
      abhishek123323 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      719
    2. 2
      ATLien_0
      278
    3. 3
      Michael Scrip
      205
    4. 4
      +FloatingFatMan
      193
    5. 5
      Steven P.
      129
  • Tell a friend

    Love Neowin? Tell a friend!