locked
Last mail not sending from console application, Please help !!! RRS feed

  • Question

  • Hi,

    I am pulling my hair!!!, I just can't find why .NET is not sending the last mail, this is a brief descripction of what I am doing:

    For I as int16 = 0 to employeeList.Count -1
       SendReceipt '<---Sends OK
    Next
    
    SendMailToAministratator '<---Not sending

    So every mail inside the For is sent correctly, the problem is the mail to teh administrator.

    I have debbuged the application, line by line, and the following code (which is the same to send mails inside For) and says it was sent, NO ERRORS !!!, but never arrives to the mail server, I am driving crazy with this!!!

            Dim Client As New Net.Mail.SmtpClient(SMTPServer)
            Dim SmtpUser As New System.Net.NetworkCredential()
            Dim AddressTo As String = AddressToMails
            Dim msg As New Net.Mail.MailMessage
            msg.From = New MailAddress(AddressSending, NameSending)
            msg.To.Add(New MailAddress(AdressTo))
    
            msg.IsBodyHtml = True
            msg.BodyEncoding = System.Text.Encoding.UTF8
            
            msg.Subject = Subject
    
            SmtpUser.UserName = SMTPuser
            SmtpUser.Password = SMTPpass
    
            Client.UseDefaultCredentials = False
            Client.Credentials = SmtpUser
            msg.Body = Body
            Client.Port = 576
            Client.Send(msg)
            
    Any ideas?....please


    G.Waters

    Wednesday, June 28, 2017 3:10 PM

Answers

  • Well, it seems that since it is an application console project an sending the administrator mail was the last thing to do and since the mail has an attachment of 10mb, it came to my mind that maybe the exe ended before sending the mail completely. 

    I added a timer of 10 seconds right after the Client.Send(msg) and voila!!!, now it's working, very weird thou....

    I appreciate all of you for your help

    Thanks


    G.Waters

    Wednesday, June 28, 2017 5:25 PM

All replies

  • Check the SMTP server logs and see what they say happened to the message.  If there is an outbound filtering service, check its logs as well.

    If you get no error from Client.Send(msg) then the email was created and submitted to the SMTP server.  The server is either failing to send the email out to the recipient, or the recipient's server (or local client) is blocking the message.

    Check your mail logs and go from there.  It does not appear to be a problem with the code you've posted.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, June 28, 2017 3:19 PM
  • Hi Reed,

    I have checked STMP logs and the last mail never gets to server.

    I have sent a mail to the recipient using outlook and the same mail server and it gets to the user correctly.

    Any ideas?


    G.Waters

    Wednesday, June 28, 2017 3:27 PM
  • Hi Reed,

    I have checked STMP logs and the last mail never gets to server.

    I have sent a mail to the recipient using outlook and the same mail server and it gets to the user correctly.

    Any ideas?


    G.Waters


    Can you show the full code of both methods (SendReceipt and SendMailToAdministrator)?

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, June 28, 2017 3:42 PM
  • Hello,

    I would advise using SendCompleted event to see if there are errors or if it reports success.

    https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.sendcompleted(v=vs.110).aspx?f=255&MSPPError=-2147217396&cs-save-lang=1&cs-lang=vb#code-snippet-2

    You could also setup the SMTP object to send emails to a physical folder which is a litnus test.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, June 28, 2017 4:24 PM
  • Well, it seems that since it is an application console project an sending the administrator mail was the last thing to do and since the mail has an attachment of 10mb, it came to my mind that maybe the exe ended before sending the mail completely. 

    I added a timer of 10 seconds right after the Client.Send(msg) and voila!!!, now it's working, very weird thou....

    I appreciate all of you for your help

    Thanks


    G.Waters

    Wednesday, June 28, 2017 5:25 PM
  • Hi Grirge,

    Glad to hear this issue has been solved by yourself. Thanks for your sharing, I will introduce this experience to other forum users who face the same condition. Please mark your reply to close this case.

    Thanks for your understanding.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 30, 2017 1:16 AM