Why does this timeout?
Dim s As New SmtpClient
s.Host = "smtp.gmail.com"
s.Port = 465
s.EnableSsl = True
s.Timeout = 5000
s.Credentials = New NetworkCredential("my.name#gmail.com", "mypassword")
Dim m As New MailMessage
m.To.Add("my.name#gmail.com")
m.From = New MailAddress("my.name#gmail.com")
m.Body = "Test Message"
m.Subject = "Test Subject"
s.Send(m)
These settings come straight from my Outlook Express test setup, and it can send fine.
Set really long timeout = does nothing
Change port numbers to 587 or 25 = does nothing
One thought: Outlook Express has a "My server requires authentication" option, which I couldn't see an obvious equivalent for with SmtpClient. Could it be related to that?
Thanks in advance
Dave
--Trindaz on Fedang #vb.net-smtp
Edit: You might need to add the following line: s.UseDefaultCredentials = False before the line starting with s.Credentials...
Do you have a firewall or some kind of anti-virus program running that might be blocking the connections?
A good place to start is to just do a simple connect from the command line.
telnet smtp.gmail.com 465
Note, depending on Windows version you might have to enable the telnet client first, see this link for details.
You have to go into your gmail account and turn on access for less secure apps and change the port to 587
Related
Similar problem to "Resca's" Utility to send email to Gmail stopped working after google implemented OAuth. I have an excel workbook using VBA to ONLY SEND individual gmails to multiple “google group” members. It had been working for 4 years until Gmail added Oauth.
I have done tests with OAuth code from "Email Architect". I can test the app in test mode and it will send the email if I click passed the alarms and add include read. Compose, send and delete permissions. When I configure it as production I get not verified message and go through a similar routine that "test" needed. When I try to verify the Gmail API it requires a domain which I don't have. This is run under a single user xxx#gmail with owner permission from my disk. After seeing Resca's post, I think I may be over doing the OAuth.
I am not a programmer, but have vintage experience with assembler, macro and micro code, but not high level languages. Self taught VBA/Excel
I got parts of this code from "Jean-François Corbett" # https://stackoverflow.com Tonyyy at MRexcel.com
Set CDO_Mail = CreateObject("CDO.Message")
On Error GoTo Error_Handling
Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1
Set SMTP_Config = CDO_Config.Fields
With SMTP_Config
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxx#gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxx"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
'25 & 465 are valid ports and sometimes may fail. Change to the other if you can't connect
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With
With CDO_Mail
Set .Configuration = CDO_Config
End With
CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.TextBody = strBody
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send
To be clear Google did not add Oauth2. The option of using Xoauth2 with the smtp server has always been there. Nor is google forcing you to use Xoauth2 with the smtp server.
What google did was remove the option for Less secure apps & your Google Account. Which allowed you to use the google account password to connect to the smtp server.
If you have 2fa enabled on the google account you can create an apps password and use that password instead of the actual password for the google account in your code.
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "AppsPassword"
If you do not want to use an apps password then yes you will need to configure Xoauth2. xoauth2-protocol Its been a very long time since i have touched VBA I dont think this is something i can help with. But a quick google search shows it should be supported Oauth
When trying to send an email using a Visual Basic Console App I get an error: "The operation timed out". I'm sending from a Windows 7 pc. Can this be done?
I've found many posts that say it fails because there is no SMTP client on Windows 7. However, I downloaded smpt4dev and get the same results when I try to connect to that via "localhost".
But I can telnet to the server from the same pc and get no errors. I can also send an email using these telnet commands:
telnet SMTP.domain.xyz 25
helo SMTP.domain.xyz
mail from: f#domain.com
rcpt to: t#domain.com
data
subject: test email
.
quit
I have tried this with a few different smtp servers and I get the same results. I know that my server name, port, username and pw are correct.
Imports System.Net.Mail
Try
Dim SMTPClientObj As New Net.Mail.SmtpClient
SMTPClientObj.UseDefaultCredentials = False
SMTPClientObj.Credentials = New System.Net.NetworkCredential(username, password)
SMTPClientObj.Host = "mysmtpserver"
SMTPClientObj.Port = 25
SMTPClientObj.EnableSsl = False
Dim e_mail As New MailMessage()
e_mail.From = New MailAddress("test#test.com")
e_mail.To.Add("test2#test.com")
e_mail.Subject = "Email Sending Test"
e_mail.IsBodyHtml = False
e_mail.Body = "Test email from VB"
SMTPClientObj.Send(e_mail)
Dim x As New Mail.SmtpStatusCode
Console.WriteLine("SmtpStatusCode: " & CStr(x))
Console.WriteLine("Mail Sent.")
Catch ex As Exception
Dim x As New Mail.SmtpStatusCode
Console.WriteLine("SmtpStatusCode: " & CStr(x))
MsgBox(ex.Message)
MsgBox(ex.ToString)
MsgBox(ex.InnerException)
End Try
At this point I'd just like to be able to get more details on the error instead of the simple timed out message. But I've never used the SmtpStatusCode before and am not sure how to use it.
The ex.InnerException prompt is always blank.
Can you give me any pointers on how to get more detailed error info? Or what I need to do to get this to work on my windows 7 pc?
Thank you
Turns out Digital Guardian was blocking port 25. McAfee wasn't the problem nor was Group policy.
Thanks to everyone for their assistance.
I've got an emailing system in my application which I have used fine and have seen it working.
The customer has also managed to send emails using the program, however, once they've paid for the application, they're then selling it on to other customers.
They've just taken it in to test with the first customer and they're having troubles sending emails, so I investigated the error log and saw the following message:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [BN6PR2201CA0027.namprd22.prod.outlook.com]
Now, after Googling this exact error message, the top result was this question, in which it's clear to see that the OP was trying to send a message from an email address that was hard-coded as "emailaddress". However, that isn't the case for me.
My code is as follows:
recipient = eMail
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(senderAdd, senderPass)
Smtp_Server.EnableSsl = False
Smtp_Server.Host = SMTPserver
AddHandler Smtp_Server.SendCompleted, AddressOf sendComplete
e_mail = New MailMessage()
e_mail.From = New MailAddress(senderAdd)
e_mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess
e_mail.To.Add(eMail)
e_mail.Subject = subj
e_mail.IsBodyHtml = False
e_mail.Body = bod
Smtp_Server.SendAsync(e_mail, userState)
Is there anything in here which would be causing this error? If so, what is it?
The variables are all set from a database table, and if there are any null values then the system will pop a message box to alert the user of this and then exit the subroutine and not send the email, so it's not an issue with null values - The only thing I can think of is that the credentials are wrong, but they've supposedly been verified by 3 different people as correct.
You might need to specify the domain. Use this constructor of the NetworkCredential class and pass in the domain.
Smtp_Server.Credentials = New Net.NetworkCredential(senderAdd, senderPass, "expectedDomainName")
Difficult to say for sure though because we can't reproduce this issue under your same conditions.
I have been using CDO from my access application successfully for some time. We are now moving to Office (and Outlook) 365. My CDO code now doesn't work and gives a transport error 80040217. I have read that this error has to do with username and password authentication. According to our server admin I have the right information.
I have seen conflicting articles as to whether or not CDO can be used with 365. I have also tried the different port numbers (25 seems to be the right one). I also have seen older articles saying the server should be a pod id like podxxxxx.outlook.com, but then other articles say that is old and to just use smtp.office365.com.
I have no idea how to get the pod information if that is what I need.
I have attached the code I am using, but I was wondering if anyone knows whether CDO really does or does not work with 365. If it does, is there some setting we may be missing on our server? Our admin has sent an email with this address through the command line, so it appears the userid is good, but he used Base 64 encoding for the username and password. I tried that but it didn't work either.
I have also tried using the MX endpoint for the smtpserver value like myaddress-com.mail.protection.outlook.com and I still get the error.
Any suggestions?
Dim cdoConfig As Object, objMessage As Object
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.office365.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
.Item("http://schemas.microsoft.com/cdo/configuration/username")="donotreply#myaddress.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="passwordhere"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")= 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=True
.Update
End With
Set objMessage = CreateObject("CDO.Message")
Set objMessage.configuration = cdoConfig
objMessage.To = "someone#myaddress.com"
objMessage.FROM = "donotreply#myaddress.com"
objMessage.Subject = "test"
objMessage.textBody = "put the body here"
objMessage.Send
Everyone I am using vb6 to send out emails. I have come across a situation where i need to send it Secured via Jmail.
How do i send a SSL email in Jmail?
Here is my current code, I need it to work with SSL as well.
Set objEmail = CreateObject("JMail.Message")
With objEmail
.From = gcFromAddress
.FromName = gcFromAddress
.AddRecipient cEmailAddress
.Subject = "" & mrsReportData("SubdivisionName").Value
End With
objEmail.Send (gcSMTPServerAddress & ":" & gcSMTPServerPort)
Use .net for that is very easy
First create dll proyect in .net example here (http://jumbloid.blogspot.com/2009/12/making-net-dll-com-visible.html)
second use it in vb6
Don't know what JMail is, however, here's code for sending mail per SSL from VB:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=71899&lngWId=1
A quick check of the code however has shown it is quite buggy. Maybe however it is a good hint how to implement.