Validate email address on exchange server - vb.net

I'm allowing users to manage a distribution list stored in a database. Users are only allowed to enter emails that are #mydomain.com. A web based application then takes the distribution list and sends emails. I'd like to validate that the email is valid before sending an email from the application.
To send an email I'm using this code:
Dim SendTo As String = "ThisIsNotARealEmailAddress#mydomain.com"
Dim SentFrom As String = "me#mydomain.com"
Dim MessageBody As String = "blah blah blah"
Dim MessageSubject As String = "This is the subject"
Dim mm As New MailMessage(SentFrom, SendTo)
mm.Subject = MessageSubject
mm.IsBodyHtml = False
mm.Priority = MailPriority.High
mm.Body = MessageBody
Dim smtp As New SmtpClient()
smtp.Send(mm)
If the SendTo is not a valid email address the server returns this error:
Mailbox unavailable. The server response was: 5.1.1 <ThisIsNotARealEmailAddress#mydomain.com>... User unknown
Is there anyway to validate the email when the email address is added to the database, instead of a try catch block when sending the email?

The users are only sending to your domain? And you control the domain? And its a windows domain? Just query the AD and get their email address from the AD without asking them. Would that be valid? I presume this is a windows application, not a web app.

Related

vb.ne send email from a shared mailbox

i'm supposed to send an email as customer care from a shared mailbox to several addresses of my company customers.
i'm using mailkit library and i use this code
Code:
Dim contenutomail As New MimeKit.BodyBuilder
Dim smtpclient As New MailKit.Net.Smtp.SmtpClient
Dim mail As New MimeKit.MimeMessage
smtpclient.Connect("smtp.office365.com", 587, MailKit.Security.SecureSocketOptions.StartTls)
smtpclient.Authenticate("eurostar_italia#mycompany.com", "Aprile22")
mail.From.Add(New MimeKit.MailboxAddress("", "customeroffice#mycompany.com"))
For i = 0 To mailinglist.Count - 1
mail.Bcc.Add((New MimeKit.MailboxAddress("",mailinglist(i).ToString)))
Next
contenutomail.TextBody = ""
contenutomail.HtmlBody = "hello world"
mail.Body = contenutomail.ToMessageBody
smtpclient.Send(mail)
smtpclient.Disconnect(True)
the problem is : sent mail are save in MY personal account SENT mailbox instead of shared SENT mailbox.
I don't have any Admin right to modify the office365 sharedmailbox.
can anyone help me ? i don't want to save a copy,i want the mail sent to be saved in the sent shared mailbox
i can't solve it
thanks
fabio

Outlook and Office 365 does not show sent items where mails were sent using a external software which is developed using vb.net

We have a mail-id in our own domain.
We configure it in outlook along with office 365.
We have using a software for our business purpose which is developed using vb.net.
Using this software, we are sending mails to our customers from the mail-id of our own (For Example user#mydomain.in).
Customers also receive the mail properly.
The problem is that we can't able to see the sent mails in our "sent items" of both outlook and office365.
Sent items does not sync.
Dim mailbody As String = ""
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("user#mydomain.in", "password")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.office365.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress("user#mydomain.in")
Dim attachment As System.Net.Mail.Attachment
e_mail.To.Add(New_Enquiry.MAIL_ID.Text)
e_mail.Subject = "Thankyou for your Enquiry"
e_mail.IsBodyHtml = True
Smtp_Server.Send(e_mail)
These are the code which I have used in vb.net.
It works properly but unable to see the sent mails in sent items.
I had used the same code for gmail also and Gmail shows the sent mails in sent items.
Kindly spot me the error.
Gmail is special: anything you send through their SMTP server will show up in your Sent folder. This is not standard behaviour: if you want messages to show up in your Sent folder, you have to PLACE them there, generally using IMAP and the APPEND command. If you have the right access, you may be able to make some sort of server side script to do this for you, but it is not the default.

SMTP outgoing server does not send text inside the email by vb.net

I developed apart of an application that sends emails to partners and clients with a saved email subject and text; so i used the vb.net settings to declare variables to be initiated with the program. and then asked the user to save his email subject and body to be used again later.
the problem is when i attemped to send the email, the email reaches the otherside yet with no content at all ( mail subject and body are null).
some points may be taken into consideration:
i used background worker (thread dirrent than the UI thread)
the outgoing mail is SMTP (Gmail server).
I passes the Body and the subject as strings to the sub sendmail().
Is there any better method to store mail's body and subject instead of string variables ?
I am sure that the SMTP took all my strings
Sub sendmail(receiver As String, mailsubject As String, mailbody As String, mailattachement As String)
Dim email As New System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient
Try
With smtp
.EnableSsl = My.Settings.mailssl
.Port = My.Settings.mailport
.Host = My.Settings.mailhost
.Credentials = New Net.NetworkCredential(My.Settings.mailaddress, My.Settings.mailpassword)
End With
With email
.From = New System.Net.Mail.MailAddress(My.Settings.mailaddress)
.Subject = severalclientmailsubject
.Body = severalclientmailbody
.To.Add(receiver)
End With
smtp.Send(email)
Catch ex As Exception
'Generic Exception raised.
changestatus2("General Error.")
End Try
End Sub
what could can cause this thing ?!?

Use CDO Send Emails in Excel VBA Not Working

I am trying to send email within Excel VBA. Based on my research on Internet, I enabled Microsoft CDO for Windows 2000 Library and composed my VBA codes as below:
Sub SendCDOMail()
Dim objCDOMsg As Object
Set objCDOMsg = CreateObject("CDO.Message")
'CDO Configuration
With objCDOMsg.Configuration.Fields
'
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Server port (typically 25, 587)
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
'SMTP server IP or Name
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'SMTP Account User ID
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxx#bbbb.com"
'SMTP Account Password
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxxx"
'Use SSL for the connection (False or True)
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Update
End With
'CDO Message
objCDOMsg.Subject = "TEST Subject"
objCDOMsg.From = "xx#xx.com"
objCDOMsg.To = "xx#xx.com"
objCDOMsg.TextBody = "TEST Body"
objCDOMsg.Send
End Sub
However, I received the error saying:
The server rejected the sender address. The server response was: 530.5.7.57 SMTP;
Client was not authenticated to send anonymous mail during MAIL FROM
I also tried the same configurations using PowerShell and it worked (smtpserver, username, password, server port...).
I don't know where it might go wrong.
Here it is: https://technet.microsoft.com/en-us/library/mt210446(v=exchg.150).aspx - note that this is in the Office365 section for "How to set up a multifunction device or application to send email using Office 365,", so there may be other things in there for you too.
This indicates that you are connecting to the SMTP client submission endpoint (smtp.office365.com), which can't be used for direct send. For direct send, use the MX endpoint for your Office 365 tenant, which ends with "mail.protection.outlook.com." You can find your MX endpoint by following the steps in Full configuration instructions for direct send.

Email Function in VB

I need a simple email function that just sends an email (not looking to spam anyone I promise!).
Anyone, anyone? Using VB 2008
Use the SmtpClient class to do this. There's an example of sending an email asynchronously on the documentation page, but here's a basic way of doing it:
Dim client As New SmtpClient("mail.myisp.com")
Dim fromAddr As New MailAddress("jane#contoso.com")
Dim toAddr As New MailAddress("ben#contoso.com")
Dim message As New MailMessage(fromAddr, toAddr)
message.Body = "This is a test e-mail message sent by an application. "
message.Subject = "test message 1"
client.Send(message)