I am trying to send a mail using Dart Control. It was working well with a particular server, but since I switched to a secured server, I receive the following error message:
Protocol Exception--
Request: AUTH LOGIN
Response: 530 Must issue a STARTTLS command first
Below is the code :
Dim Smtp1 As Smtp = New Smtp
Dim SMTPResult As SmtpResult
Dim Message As Dart.Mail.MailMessage = New Dart.Mail.MailMessage()
Smtp1.Session.RemoteEndPoint.Port = intPortNo
strErrLoc = "SMTP1.DnsServerTimeout"
Smtp1.DnsServerTimeout = 15 'default time out 30 seconds
strErrLoc = "Set User Name"
Smtp1.Session.Username = strUserID
Smtp1.Session.Password = strPWD
strErrLoc = "Subject and Mail TEXT"
Message.Subject = strSubject
If strHTMLEmail.Trim = "" Then
Message.Text = strMailText
Else
Message.Html = strHTMLEmail
End If
Smtp1.Session.Authentication = Authentication.Auto
Smtp1.Session.RemoteEndPoint.HostNameOrAddress = strServerName.Trim
Smtp1.Session.ServicePrincipleName = "SMTP/" & strServerName.Trim
SMTPResult = Smtp1.Send(Message)
try with enabling SSL mode,like
Smtp1.EnableSSL = True
this works in case of Gmail ,Please Check with yours.
The suggestion is to use Explicit security.
The following Code implementing Explicit Security resolved the issue.
Smtp1.Session.Security.Encrypt = Encrypt.Explicit
Related
I'm writing a program to send internal emails in VB.Net using the official Microsoft Graph package. At first I got it to send calendar invites and that worked fine for months, but when I tried to add the ability to send emails I keep getting an Internal Server Error.
From looking at other times people have got this error from Graph, it appears to be when a malformed request is sent or when values that don't quite make sense are given. I'm using the constructors from the package and using basically the same construction method as every example online, so the structure of the request can't be wrong, and the only fields that I'm using just take text and don't do anything with it, so I don't think that can be the issue either.
I have the correct permissions in Azure: Screenshot of permissions in Azure, including Mail.Send
Here's my code for constructing the email:
Function DefineImportantEmail(Locations As String, Recipients As List(Of (String, String))) As Message
Dim title = "IMPORTANT OUTAGE NOTIFICATION"
Dim message = "Outage at " & Locations
Dim RecipientList = New List(Of Recipient)
For Each recipient In Recipients
RecipientList.Add(New Attendee With {
.EmailAddress = New EmailAddress With {
.Address = recipient.Item1,
.Name = recipient.Item2
},
.Type = AttendeeType.Optional
})
Next
Return New Message With {
.Subject = title,
.Body = New ItemBody With {
.ContentType = BodyType.Text,
.Content = message
},
.ToRecipients = RecipientList
}
End Function
And here's the code I use to send the email:
Sub SendImportantEmail(Locations As String, Recipients As List(Of (String, String)))
Dim SaveToSentItems = True
Dim graphClient = GetGraphClient()
Dim EventObject = DefineImportantEmail(Locations, Recipients)
Dim request = graphClient.Users("xxxxx#xxxxxxxxxxxxxxx.com").SendMail(EventObject, SaveToSentItems).Request().PostAsync()
request.Wait()
End Sub
The GetGraphClient function works for any other API endpoint I've tried, so I haven't included it. The censored user is from our organisation and is also the user I sent calendar invites from in the first version of this program.
Here's the full error message I get:
(Code: ErrorInternalServerError
Message: An internal server error occurred. The operation failed.
ClientRequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
)
---> Status Code: InternalServerError
Microsoft.Graph.ServiceException: Code: ErrorInternalServerError
Message: An internal server error occurred. The operation failed.
ClientRequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
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
So I am working on setting up a new (private) bot for Microsoft Teams that should be able to post messages in a channel on-demand. I already have a bot coded for Google Hangouts Chat, but Microsoft Teams is giving me a really hard time.
I've been searching for over 10 hours now all over the web, and I am very confused.
Right now, all I want to do is post cards to a Microsoft Teams Channel. So I created the connectorclient, I used the baseuri provided when the bot joined the channel (Starts with smba.trafficmanager.net) with my MSAppID and MSAppPassword. Then, I fill in as much information as I can (Maybe too much?) and I submit the information using the connector's .conversations.createconversation.
Namespaces used: Microsoft.bot.connector, Microsoft.bot.connector.teams.models
Here's the code:
Dim Connector As New ConnectorClient(New Uri("https://smba.trafficmanager.net/amer/"), "MSAPPID", "MSAPPPASSWORD")
Dim conversation As New ConversationParameters
Dim activity2 = Activity.CreateMessageActivity
Dim bot As New ChannelAccount
bot.Id = "BOTID"
bot.Name = "EDD Bot Test"
conversation.Bot = bot
Dim chaninfo As New ChannelInfo
chaninfo.Id = "CHANID"
chaninfo.Name = "General"
Dim teaminfo As New TeamInfo
teaminfo.Id = "TEAMID"
teaminfo.Name = "EDD"
activity2.Text = "Test"
activity2.ServiceUrl = "https://smba.trafficmanager.net/amer/"
activity2.Type = ActivityTypes.Message
activity2.From = bot
activity2.ChannelId = "msteams"
Dim tenantdata As New TenantInfo
tenantdata.Id = "TENANTID"
Dim teamschanneldata As New TeamsChannelData
teamschanneldata.Channel = chaninfo
teamschanneldata.Team = teaminfo
teamschanneldata.Tenant = tenantdata
activity2.ChannelData = teamschanneldata
conversation.Activity = activity2
Response.Write(JsonConvert.SerializeObject(conversation))
Try
Dim reqresp As ConversationResourceResponse = Connector.Conversations.CreateConversation(conversation)
Response.Write("ActivityID: " & reqresp.ActivityId & ", ServiceURL: " & reqresp.ServiceUrl & ", ID: " & reqresp.ServiceUrl)
Catch ex As ErrorResponseException
Response.Write(ex.Response.Content & " " & ex.Response.ReasonPhrase)
End Try
This is what the API returns:
{"message":"Authorization has been denied for this request."} Unauthorized
Keep in mind, I'm not even 100% sure I'm using the right method to create the channel message, I figured it was either CreateConversation or ReplyToActivity.
I gave the app Users.ReadWriteAll permissions too, so am I missing something? That error leads me to think it doesn't have anything to do with the ConversationParameters payload but something to do with authentication.
Problem was solved by using MicrosoftAppCredentials.TrustserviceUrl for both the serviceUrl and the endpoint message.
Running the Excel VBA code below I get the following error:
Run-time error -2147220973
The transport failed to connect to the server
Public Function send_email()
Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "mymail#gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypass"
.Update
End With
' build email parts
With cdomsg
.To = "mymail#gmail.com"
.From = "mymail#gmail.com"
.Subject = "the email subject"
.TextBody = "the full message body goes here. you may want to create a variable to hold the text"
.Send
End With
Set cdomsg = Nothing
End Function
Trouble source
A typo caused this mess - smptserverport should be smtpserverport!
Things I tried
On the way to solve this issue, I tried many things. But now I'm not so sure if all were actually needed.
still, someone might gain something from the list:
Enable "Less Secure App"
Open "Display Captcha" before testing connection
Make sure you have a strong password
App Passwords are no longer recommended
2 Step Verification is not a must - but highly recommended!
Few tips:
Port 465 should be in use when sending the password in clear text
Port 587 should be used when sending a secure password.
if you need to have secure password within VBA/VBS, you can use this little trick with PowerShell (source):
Dim myPassword, cmd, shell, executor, securePassword
myPassword = "ABCABCABC....."
cmd = "powershell.exe ConvertTo-SecureString "& myPassword
Set shell = CreateObject("WScript.Shell")
Set executor = shell.Exec(cmd)
executor.StdIn.Close
securePassword = executor.StdOut.ReadAll
Now I am using the bellow code and it works fine.
Don't forget to change your gmail config to allow sending email from other apps.
Sub sendEmail(gmail, password, targetEmail, subject, bodyContent)
Dim Mail As New Message
Dim Config As Configuration: Set Config = Mail.Configuration
Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "smtp.gmail.com"
Config(cdoSMTPServerPort) = 465
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = gmail
Config(cdoSendPassword) = password
Config.Fields.Update
Mail.To = targetEmail
Mail.from = Config(cdoSendUserName)
Mail.subject = subject
Mail.HTMLBody = bodyContent
Mail.Send
End Sub
I currently have a mail system using Microsoft's exchange server (OWA). I am trying to authenticate a user and send an email using pure Visual Basic code.
I have been trying to use a library called Aspose, however; I have no idea if I'm on the right track. I can not get it to work and I am not sure (since this is a company mail server) whether it's the server or it's my code.
Currently I have,
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
I have obviously changed the username, password, and server name fields to generic ones but with (what I think is the right credentials) the output is always failed.
Can anybody help me out please?
Here is what I use:
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
The ExchangeClient class is used to connect to Exchange server using the WebDav protocol and is used with Exchange Server 2003 and 2007. For OWA, you need to use the IEWSClient interface as shown in the following sample code. It has an Office365 test account that you can use to send a test email (the test account is solely for testing purpose and is not property of Aspose. I just created it for assisting you in testing the functionality). Please try it and if you face any problem, you may share the porblem on Aspose.Email forum for further assistance.
' 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)
I work with Aspose as Developer evangelist.