Question Sending an email fom a windows service

Bill-e

Member
Joined
Jan 24, 2012
Messages
9
Programming Experience
3-5
Hi I have a windows service which needs to send an email every couple of hours if a variable becomes true.

I tested my code in a windows form and the same code does nothing in the windows service.

here's what I have:


VB.NET:
Imports System.Net.Mail

Public Sub SendSMTP(ByVal strFromAddress As String, ByVal strFromName As String, ByVal strToAddress As String, ByVal strToName As String, 
ByVal strReplyToAddrr As String, ByVal strReplyToName As String, ByVal strSubject As String, ByVal strBody As String, ByVal strCC As String, ByVal strAttachments As String)
        Dim insMail As New MailMessage(New MailAddress(strFromAddress, strFromName), New MailAddress(strToAddress, strToName))
        With insMail
            .Subject = strSubject
            .Body = strBody
            .ReplyTo = New MailAddress(strReplyToAddrr, strReplyToName)
            .IsBodyHtml = True
            If Not strAttachments.Equals(String.Empty) Then
                Dim strFile As String
                Dim strAttach() As String = strAttachments.Split(";")
                For Each strFile In strAttach
                    .Attachments.Add(New Attachment(strFile.Trim()))
                Next
            End If
        End With


        Dim smtp As New System.Net.Mail.SmtpClient
        smtp.UseDefaultCredentials = False
        smtp.Credentials = New System.Net.NetworkCredential(My.Settings.fromAddress, My.Settings.mailPassword)
        smtp.Host = My.Settings.SMTPServer
        smtp.Port = 25
        smtp.Send(insMail)


    End Sub

Nothing happens... no email no error nothing...

Is there anything I can do here? Is it a permissions thing? I've gve the service a number of different users but nothing has worked.

Please help,

TIA

Bill
 
As crazy as it sounds, you might want to check the order that you're setting the message properties - I've seen issues in the past that were purely down to the order those get set (although I can't recall what the wrong/correct order was)
 
Thanks for the replies guys!

The initial suggestion of more debugging identified the issue here. It's annoying because the problem was actually a date time conversion mixup in a parameter I was passing in...

Thanks anyway guys!
 
Back
Top