VB在Outlook Web App中验证用户

时间:2015-07-09 19:11:13

标签: vb.net aspose

我目前有一个使用微软交换服务器(OWA)的邮件系统。我正在尝试验证用户并使用纯Visual Basic代码发送电子邮件。

我一直在尝试使用名为Aspose的库;我不知道我是否走在正确的轨道上。我不能让它工作,我不确定(因为这是一个公司的邮件服务器)它是服务器还是它的代码。

目前我有,

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Create instance of ExchangeClient class by giving credentials
        Dim client As Aspose.Email.Exchange.ExchangeClient = New Aspose.Email.Exchange.ExchangeClient("https://MAILSERVER.com/username/", "username", "password", "https://MAILSERVER.com/")

        ' Create instance of type MailMessage
        Dim msg As Aspose.Email.Mail.MailMessage = New Aspose.Email.Mail.MailMessage()
        msg.From = "username@MAILSERVER.com"
        msg.To = "receivingemail@gmail.com"
        msg.Subject = "test"
        msg.HtmlBody = "test"

        ' Send the message
        Try
            client.Send(msg)
            Console.WriteLine("made it")
        Catch ex As Exception
            Console.WriteLine("failed")
        End Try
    End Sub

我显然已将用户名,密码和服务器名称字段更改为通用字段,但使用(我认为正确的凭据)输出始终为failed

有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:0)

以下是我使用的内容:



    Public Shared Function SendEMail(MailMessage As System.Net.Mail.MailMessage) As String
	ErrorMess = ""
	' Default the from address, just in case is was left out. 
	If MailMessage.From.Address = "" Then
	    MailMessage.From = New Net.Mail.MailAddress("donotreply@MAILSERVER.com")
	End If
	' Check for at least one address
	If MailMessage.To.Count = 0 AndAlso MailMessage.CC.Count = 0 AndAlso MailMessage.Bcc.Count = 0 Then
	    ErrorMess = "No Addresses Specified"
	    Return ErrorMess
	End If
	' Create a SMTP connedction to the exchange 2010 load balancer.
        Dim SMTPClient As New System.Net.Mail.SmtpClient("MAILSERVER.com")
	Try
	    Dim ValidUserCredential As New System.Net.NetworkCredential
	    ValidUserCredential.Domain = "MAILSERVER.com"
	    ValidUserCredential.UserName = My.Resources.EmailUserName
	    ValidUserCredential.Password = My.Resources.EmailPassword

	    SMTPClient.UseDefaultCredentials = False
	    SMTPClient.Credentials = ValidUserCredential
	    SMTPClient.Send(MailMessage)
	    Return "Mail Sent"
	Catch ex As Exception
            ErrorMess = ex.Message & " " & ex.InnerException.ToString
	    Return ErrorMess
	End Try
    End Function




答案 1 :(得分:0)

ExchangeClient类用于使用WebDav协议连接到Exchange服务器,并与Exchange Server 2003和2007一起使用。对于OWA,您需要使用IEWSClient接口,如以下示例代码所示。它有一个Office365测试帐户,您可以使用它来发送测试电子邮件(测试帐户仅用于测试目的而不是Aspose的属性。我刚创建它以帮助您测试功能)。请尝试一下,如果您遇到任何问题,可以在Aspose.Email forum分享问题以获得进一步的帮助。

' Create instance of IEWSClient class by giving credentials
Dim client As IEWSClient = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "UserTwo@ASE1984.onmicrosoft.com", "Aspose1234", "")
' Create instance of type MailMessage
Dim msg As New MailMessage()
msg.From = "UserTwo@ASE1984.onmicrosoft.com"
 msg.[To] = "receiver@gmail.com"
msg.Subject = "Sending message from exchange server"
msg.IsBodyHtml = True
msg.HtmlBody = "<h3>sending message from exchange server</h3>"

' Send the message
client.Send(msg)

我与Aspose一起担任开发人员传播者。