Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click 'Address of email sender Dim ccEmail As String = txtemail.Text 'Create the msg object to be sent Dim msg As New MailMessage() 'Add your email address to the recipients msg.[To].Add("office365emailaccount") 'Configure the address we are sending the mail from Dim fromEmail As New MailAddress(ccEmail) msg.From = fromEmail 'Append their name in the beginning of the subject msg.Subject = "Testing Office365 email account" 'To embed image in email msg.Body = "If you receive this email, then office365 email account is working from DMZ server" ' msg.Attachments.Add(New Attachment(New MemoryStream(bytes), lblEmpName.Text & DateTime.Now.Ticks & ".pdf")) msg.IsBodyHtml = True 'Configure an SmtpClient to send the mail. Dim client As New SmtpClient("xxx.xxx.x.xxx") 'Exhange IP Address client.Host = "smtp.office365.com" client.Credentials = New System.Net.NetworkCredential("dmzuser", "mydmzpassword") 'client.DeliveryMethod = SmtpDeliveryMethod.Network client.EnableSsl = True client.Port = 25 'Send the msg client.Send(msg) lblMsg.Text = "Success!" End Sub
From novice to tech pro — start learning today.