-1

I'm trying to send an email through exchange server using Exchange Web Services (EWS). I've configured some parameters but it can't send. I've tried other methods, like third party assemblies, and with that is possible to send, because of that I think I've missed some parameters or method to configure my connection.

I hope you can help me.

I've pasted some code below ...

        Try
            Dim vFrom As String = "mail@domain.exchange.com"
            Dim vTo As String = "personal@mydomain.es" 
            Dim vSubject As String = "Test " & DateTime.Now.ToString
            Dim vBody As String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit ..."
            Dim vHost As String = "webmail.domain.exchange.com"
            Dim vUsr As String = "boss@mydomain.es"
            Dim vPsw As String = "1234567890" 

            Dim service As New ExchangeService(ExchangeVersion.Exchange2007_SP1)
            service.Credentials = New WebCredentials(vUsr, vPsw, vHost)
            service.Url = New System.Uri("https://" & vHost)

            Dim mail As New EmailMessage(service)
            mail.From = vFrom
            mail.ToRecipients.Add("John", vTo)
            mail.Subject = vSubject
            mail.Body = vBody
            mail.SendAndSaveCopy()

        Catch ex As ServiceRequestException
            MsgBox(ex.Message + " - sendMailExchange(ServiceRequestException)")
        Catch ex As WebException
            MsgBox(ex.Message + " - sendMailExchange(WebException)")
            'Catch ex As SmtpException
            '    MsgBox(ex.Message + " - sendMailExchange(SmtpException)")
        Catch ex As Exception
            MsgBox(ex.Message + " - sendMailExchange(Exception)")
        End Try

Thanks for help...

Sam Makin
  • 1,526
  • 8
  • 23
pasta0126
  • 3
  • 1
  • 4

3 Answers3

0

Thanks for posting the additional info. With it I was able to identify someone with the same issue.

Have a look at this answer: https://stackoverflow.com/a/13517513/2319909

It appears that your username variable for the WebCredentials may be wrong.

Community
  • 1
  • 1
Sam Makin
  • 1,526
  • 8
  • 23
  • I've tried too like : "domain\user" and "user@domain.es" and only "user" because my email domain is different of my domain server... my email is like name@some.domain.es and my domain is only domain.es... I've tried all I could imagine... – pasta0126 Feb 19 '15 at 13:59
  • 401 is unauthorized access, so it is permissions. Sorry cant help more. – Sam Makin Feb 19 '15 at 14:28
  • Ok... Thanks!!! I'll try to find some information about this issue with my company's system IT dept. – pasta0126 Feb 20 '15 at 07:18
0

Assuming you are doing this against an on-premise Exchange server on your corporate network, try replacing WebCredential with System.Net.NetworkCredential.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
  • Yes, I've tried to use de NetworkCredential instead of WebCredentials but the results are the same. I've got the correct server address but now instead of 401 error I get the 405 error (not permitted) But is unable to send the email. Someone has something new that I can try? Thanks all for your efforts. – pasta0126 Feb 23 '15 at 10:19
  • I would recommend downloading EWSEditor from http://ewseditor.codeplex.com/ and checking if it can connect to your server. It could be that there's an issue with how the server's configured. – Jason Johnston Feb 23 '15 at 14:42
0

I know this is an old thread ... but since I had a similar problem today for which I found the solution I thought I would let you know ...

The issue is the URI you are using. Instead of "https://webmail.domain.exchange.com" you should try "https://webmail.domain.exchange.com/EWS/Exchange.asmx"

Joachim
  • 16
  • 1
  • Link only answers do not work well here, when the link dies the answer is without value. see {Referencing](https://stackoverflow.com/help/referencing) for improving your answer. – James Jenkins Aug 08 '18 at 16:39