• 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

    • GPUs selling higher than their MSRP is the new norm it seems. This shouldn't surprise anyone. Dumb duopoly, if Intel could just stop shooting itself in the foot and release some more cards and undercut the other two that'd be great.
    • I saw that recently, and the thing that would be useful also would be to have the PC model in that spec card as well. I know that it's on the main portal page of System, but repeating it in this "Device specs" module, especially if it's meant for the main specs of the computer, would certainly be useful.
    • Do you want a little in the ground or a lot in the air?
    • Bethesda readying two updates for Oblivion Remastered targeting bugs and performance by Pulasthi Ariyasinghe The surprise release of The Elder Scrolls IV: Oblivion Remastered was a massive success for Bethesda and Microsoft, with the title going on to gain over four million players in just three days at launch while also breaking franchise records for concurrent players. While reactions to the game have been positive from both critics and players, plenty of complaints have since been pouring in about the state of the remaster. Now, Bethesda is aiming to push out updates to resolve these concerns. Today, the company revealed that two updates are currently planned for the RPG, both with different scopes. The first of these is already available in beta form to Steam players. It seems Bethesda is using the same beta update format it uses for Starfield for this Elder Scrolls entry as well. "Thanks for all your excitement and feedback since the launch of The Elder Scrolls IV: Oblivion Remastered," said the development team today. "We are actively working on two separate updates to be launched in the coming weeks, both of which will come to our Steam Beta first, before being released to all other platforms." According to the studio, the first update is focused on "quests, major bugs and blockers, and quality of life fixes. " Following the June 5 launch on the Steam beta platform, all other PC players, as well as those on Xbox Series X|S, PlayStation 5, and Game Pass subscribers, will receive the update on June 11. The beta changelog for Update 1.1 can be seen here, with bug fixes coming for the UI, gameplay, quests, and more. Multiple crashes have been resolved here, with many being related to loading saves and exploring specific locations. Instances of infinite loading, alt-tab freezing, resetting settings, and more are being targeted with fixes, too. To opt into the Elder Scrolls IV: Oblivion Remastered beta update, Steam players can head into the game's properties, select Betas, and choose the [beta] branch to receive the new build. While Bethesda hasn't revealed any release dates for the second update, it did say that improving performance will be its main focus. This is a major point of criticism for the title at the moment, so the update can't come soon enough.
    • I wouldn't consider it harsh, but companies want as many loopholes and exceptions as possible. I agree on wanting everything to be above board. Hopefully they find a way to do this.
  • Recent Achievements

    • Week One Done
      jbatch earned a badge
      Week One Done
    • First Post
      Yianis earned a badge
      First Post
    • Rookie
      GTRoberts went up a rank
      Rookie
    • First Post
      James courage Tabla earned a badge
      First Post
    • Reacting Well
      James courage Tabla earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      408
    2. 2
      +FloatingFatMan
      181
    3. 3
      snowy owl
      179
    4. 4
      ATLien_0
      171
    5. 5
      Xenon
      135
  • Tell a friend

    Love Neowin? Tell a friend!