How to check an email address smtp host? - vb.net

Im trying to send an email using System.Net.Mail,the SmtpClient instance requires a host specified, the issue is, i need it to be able to send the email with any mail i pass in the credentials.
In most cases it will be just a matter of using "smtp."+"whatever is after the #",but in some cases like outlook using stmp.live, and business with mails like something#mybusiness.com that are in reality gmail that wouldnt be an option
Is there any way to get the smtp server using just the email address?
SmtpServer = New SmtpClient()
With SmtpServer
.UseDefaultCredentials = False
.Credentials = New Net.NetworkCredential("something#something.com", "somePassword")
.Host = "smtp_from_that_random_email"
.Port = 587
End With

Related

The server response was: Authentication required even though authentication is provided

IONOS are not helpful. Especially as all of a sudden, a form stops sending an email.
This article explains and helps very well Sending email from webform using SMTP server
The error I get is the same: The SMTP server requires a secure connection or the client was not authenticated. The server response was: Authentication required
Here's my VB - I took on board the advice here and made the From the same as the authentication but still no luck. Originally it was objMM.From = New MailAddress(txtEmail.Text). I did also read that port 25 could work but this didn't work either. It was originally 587.
Sub btnSendFeedback_Click(sender as Object, e as EventArgs)
'Create an instance of the MailMessage class
Dim objMM as New MailMessage()
'Set the properties - send the email to the person who filled out the
'feedback form.
objMM.To.Add("receiver#receiver.com")
objMM.From = New MailAddress("website#domain.co.uk")
'Send the email in text format
objMM.IsBodyHtml = False
'Set the priority - options are High, Low, and Normal
objMM.Priority = MailPriority.Normal
'Set the subject
objMM.Subject = "Subject"
'Set the body
objMM.Body = " various long boring fields here . . . "
Dim smtp As New SmtpClient()
smtp.Host = "smtp.ionos.com"
smtp.EnableSsl = True
smtp.UseDefaultCredentials = False
smtp.Credentials = New Net.NetworkCredential("website#domain.co.uk", "passwordhere")
smtp.UseDefaultCredentials = True
smtp.Port = 587
'Send method of the SmtpMail class
smtp.Send(objMM)
End Sub
Is there anything else wrong here I wonder? IONOS are sure it is a script problem.
The fine manual for SmtpClient.Credentials says:
Some SMTP servers require that the client be authenticated before the server will send email on its behalf. To use your default network credentials, you can set the UseDefaultCredentials to true instead of setting [smtpClient.Credentials] property. If the UseDefaultCredentials property is set to false, then the value set in the Credentials property will be used for the credentials when connecting to the server. If the UseDefaultCredentials property is set to false and the Credentials property has not been set, then mail is sent to the server anonymously
As a result, I would expect your code to contain only one mention of UseDefaultCredentials, for purposes of setting it to False..
Unless of course, you have these same credentials configured as the default credentials in the CredentialCache.. in which case mentioning them again here is redundant

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.

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.

Click the Link to Approve the Request Form

I'm writing an approval system. In the approval system requester need to request to approve the request application. After the requester fill up the information and send the application to manager via email. The manager just need to click the link to view the application and approve the application. Now, I'm stuck to do the code for click the link for approve. Anyone Please give suggestion or code to continue my project. Thank you.
Dim mail As New MailMessage()
mail.[To].Add(AppMgr.SelectedValue)
'mail.To.Add("man#celestica.com")
mail.IsBodyHtml = True
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
'Or Your SMTP Server Address
smtp.Credentials = New System.Net.NetworkCredential("YourGmailID#celestica.com", "YourcelesticamailPassword")
'Or your Smtp Email ID and Password
smtp.EnableSsl = True
smtp.Send(mail)
Above is the code about send email to manager. Please help.

Send email from VB.Net without SMTP Gateway

I am looking for an alternative to using smtp.gmail.com as they have disabled SMTP relay at my work place. And they are adamant they will not make any exceptions.
I have written an extensive application in VB.net which captures a boat load of requirements from the user. At the end there is obviously a button to send all the captured data to some recipients. My code is as follows :
Private Sub btnEmail_Click(sender As Object, e As EventArgs) Handles btnEmail.Click
email.From = New MailAddress("kuldip.mond123#gmail.com", "Kuldip Mond")
email.Subject = "SAP Order Prerequisite Form"
email.Body = "Message Text as Body of email."
email.IsBodyHtml = True
email.To.Add("kmond#mycompany.com")
smtp.EnableSsl = True
smtp.Port = 587
smtp.Host = "smtp.gmail.com"
smtp.UseDefaultCredentials = False
smtp.Credentials = New Net.NetworkCredential("kmond#mycompany.com", "*********")
smtp.Send(email)
MsgBox("Email Sent")
End Sub
I have considered and read up on SMTP Client with gmail Apps script etc but somewhere sometime sooner or later they all boil down to using a smtp.gmail.com
Would appreciate any guidence.
Thanks in advance.
Will an SMTP gateway be available when the application is published? If so, there are a number of local SMTP host solutions for development environments.
I am in the same situation with my IT team myself (no SMTP for dev, but we have access for UAT and Live), and I use the SMTP4Dev (https://smtp4dev.codeplex.com/) application happily.
If you point to the application as your SMTP server, any e-mails sent out using it will be caught by the application and be readable by you.