how to connect to outlook.com servers using tls?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im confused as to how outlook.com email servers work when trying to send automated email messages. I have used system.net.servicepointmanager.securityprotocol = Net.SecurityProtocolType.Tls and correct port numbers but i get the error: "Unable able to connect
to remote server" in the inner exception.
Anyone sent automated email messages successfully using microsofts @edu outlook email servers?
I work for a public K-12 school and have had trouble sending mail this way.
Purpose of this automated mail message: To notify a board office personnel of changes in demographic student data.
Heres my email code ive tryed:
<pre class="prettyprint Shared Sub SendMail(ByVal [From] As String, ByVal [To] As String, _
ByVal Subject As String, ByVal Body As String, ByVal MailServer _
As String, Optional ByVal IsBodyHtml As Boolean = True, _
Optional ByVal MailPort As Integer = 25, _
Optional ByVal Attachments() As String = Nothing, Optional _
ByVal AuthUsername As String = Nothing, Optional ByVal _
AuthPassword As String = Nothing)
On Error GoTo ErrorHandler
create a SmtpClient object to allow applications to send
e-mail by using the Simple Mail Transfer Protocol (SMTP).
Dim MailClient As SmtpClient = New SmtpClient(MailServer, MailPort)
MailClient.EnableSsl = True
create a MailMessage object to represent an e-mail message
that can be sent using the SmtpClient class
Dim MailMessage = New MailMessage( _
[From], [To], Subject, Body)
sets a value indicating whether the mail message body is in Html.
MailMessage.IsBodyHtml = IsBodyHtml
sets the credentials used to authenticate the sender
If (AuthUsername IsNot Nothing) AndAlso (AuthPassword _
IsNot Nothing) Then
MailClient.Credentials = New _
System.Net.NetworkCredential(AuthUsername, AuthPassword)
System.Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls
End If
add the files as the attachments for the mailmessage object
If (Attachments IsNot Nothing) Then
For Each FileName In Attachments
MailMessage.Attachments.Add( _
New System.Net.Mail.Attachment(FileName))
Next
End If
MailClient.Send(MailMessage)
ErrorHandler:
MsgBox("My error")
End Sub[/code]
Heres the usage of the above sub:
<pre class="prettyprint Mailer.SendMail("firstname.lastname@garrard.kyschools.us", emailaddress, "Notification of Enrollment/demographic changes", "<html><head><title>Enrollment Notification Changes</title></head><body><h1>Enrollment Changes for" + Now.ToString + "</h1></center> " + todaysdata.studentname + " enrollment/demographic data has changed from" + yesterdaysdata.address + "to" + todaysdata.address + " </body></html>", "pod51004.outlook.com", True, 587, , "adminuser@garrard.kyschools.us", "adminpassword")[/code]
<br/><hr class="sig Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to
suffering - Yoda. Blog - http://www.computerprofessions.co.nr

View the full article
 
Back
Top