I'm trying to send a simple plain-text email through my VB.net web application.
I've followed the instructions here:
http://www.systemnetmail.com/faq/3.1.1.aspx
But, regardless of what email addresses I use, I keep getting the message "unable to connect to the remote server".
Here is my code
'Create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("<email1>")
mail.To.Add("<email2>")
'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"
'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)
Why is this not working?
Are you sure that your pc (127.0.0.1, loopback ip) is a SMTP server?
Dim smtp As New SmtpClient(host) means that your pc tries to connect to smtp server host and use it to send an email.
Check that and you gonna solve your problem...
Just to try: change 127.0.0.1 with the default SMTP server you use in your email software and see what happens...
More: catch the exception (if one is raised) and take note of the message...
Try to add this
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;
and review your firewall settings, maybe the port is closed.
Related
My website (I'll call it mydomain.com) is hosted on a dedicated server from 1&1 running Windows Server 2008 R2. For antivirus protection, it has AVG File Server Edition 2013. Windows Firewall is not enabled.
On that server I have installed SmarterMail and use it for all my email through a subdomain mail.mydomain.com. From my site, I send email and it's working fine.
Today I set up an account for email hosting with Rackspace and am trying to test it as a replacement for hosting on my own server. I'm testing with a different domain, myotherdomain.com. I have set up two user accounts in Rackspace as well as Outlook on my local system to send and receive email for this new domain, and it works fine in Outlook.
However, when I try to send email from my site, I get an error. Here is the VB.NET code I'm using in Page_Load of my test page:
Dim Msg As New MailMessage("orders#myotherdomain.com", "customer#yahoo.com")
With Msg
.Subject = "Email test"
.Body = "This is a test message."
.IsBodyHtml = True
End With
Dim Smtp As New SmtpClient
With Smtp
.UseDefaultCredentials = False
.Credentials = New NetworkCredential("orders#myotherdomain.com", strPassword)
.DeliveryMethod = SmtpDeliveryMethod.Network
.EnableSsl = True
.Host = "secure.emailsrvr.com"
.Port = 465
End With
Try
Smtp.Send(Msg)
lblMessage.Text = "Success!"
Catch SmtpEx As SmtpException
lblMessage.Text = "SMTP exception: " & SmtpEx.Message
If SmtpEx.InnerException IsNot Nothing Then lblMessage.Text &= " (InnerException: " & SmtpEx.InnerException.Message & ")"
Catch GeneralEx As Exception
lblMessage.Text = "General exception: " & GeneralEx.Message
End Try
I can log in to the Rackspace email portal with orders#myotherdomain.com and the value of strPassword.
The SMTP error message I get from attempting to send email from my site is: Failure sending mail. (InnerException: Unable to read data from the transport connection: net_io_connectionclosed.)
In my 1&1 Control Panel, I have configured the DNS settings for myotherdomain.com for an IP address that isn't used anywhere else, and I've defined the reverse mapping for that IP address to myotherdomain.com. I have also specified that it uses another mail server and have defined the mx0 and mx1 server names, as specified by Rackspace.
Can someone please help with ideas as to why email is not working from my site when it's the domain that is hosted on Rackspace? Thanks!
I've just come across the same issue using Rackspace SMTP. The problem is that the .net SmtpClient doesn't support Implicit SSL, which is what is provided on port 465 on that SMTP server. I switched to using port 587 and it worked correctly.
See http://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx
I have a page to create new users in our active directory using VB.NET
I’m using the following code
Dim rootEntry As New DirectoryEntry
With rootEntry
.Path = "LDAP://" & strServer & "/" & strLDAP
.AuthenticationType = AuthenticationTypes.Secure
.Username = strServerUsername
.Password = strServerPassword
End With
Dim newUser As DirectoryEntry = rootEntry.Children.Add("CN=" & strCN, "user")
With newUser
.CommitChanges()
.Properties("userPrincipalName").Value = TextPN.Text
.Properties("sAMAccountName").Value = TextAlias.Text
.Properties("givenname").Value = TextGivenname.Text
.Properties("sn").Value = TextSurname.Text
……
.CommitChanges()
.Invoke("setPassword", New Object() {strDefaultPassword})
.CommitChanges()
.Properties("userAccountControl").Value = &H0001
.CommitChanges()
End With
This code worked fine in the past.
Now we’ve migrated our webserver to Windows Server 2008 R2 and IIS 7.5, and suddenly the code is not working anymore. (.net framework is 2.0 and cannot be changed)
The user is still created in our active directory, but the account is automatically disabled and the password is not set.
Investigating this issue shows that an exception is thrown at the line
.Invoke("setPassword", New Object() {strDefaultPassword})
Exception
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
The user account which is used to connect to the AD is still the same and had domain admin rights.
Since nothing has changed to the code, I think there must be another reason why this is not working anymore? Firewall settings, IIS configuration,..?
Any ideas??
I know there is a similar case here Trying to create a new Active Directory user, Invoke("SetPassword",pwd) throws "The RPC server is unavailable"
, but this doesn’t help me out.
Check TCP/UDP 445 port is opened on your firewall.
To connect to an AD server from outside a domain, you need the following ports to be opened :
. TCP/UDP 389 (LDAP)
. TCP 3268 (GC)
. TCP/UDP 445 (SMB over IP)
DirectoryEntry.Invoke() requires AuthenticationType.Secure. What this means is that it needs to be able to authenticate the request via Kerberos or NTLM.
It attempts to use LDAPS (TCP 636) first, then falls back to CiFS (TCP445) if/when it times out or fails because of a missing or invalid certificate. If neither of these ports are open, it will fail with an "RPC Server unavailable" exception.
I have a windows application that i am using to send emails. i can send an email for any
one to his company mail directly (I am using domino server to send the mail)
for example i can send to test#landmarkgroup.com
but when i send to test#hotmail.com it is giving the following error
Transaction failed. The server response was: Relay rejected for policy reasons.
here is my code
Dim MyMailMessage As New MailMessage()
MyMailMessage.From = New MailAddress("test#landmarkgroup.com")
MyMailMessage.To.Add("harb.nayef#hotmail.com")
MyMailMessage.Subject = txtSubject.Text
MyMailMessage.Body = txtBody.Text
Dim SMTPServer As New SmtpClient("112.12.29.62")
SMTPServer.Port = 25
SMTPServer.Send(MyMailMessage)
Yes, it fails because the Domino server has been setup to not accept SMTP relays from unknown sources (to avoid spam).
Contact the admin of the Domino server so that you can set up Domino to accept relay from machines running your application (if they can be uniquely identified), or from internal hosts (if that's the case), and/or combined with a SMTP account to login to SMTP.
I am getting the following error while sending mail by click of a button in MS access form
I am using sendObject to send mail using vba code.
The host 'smtp' could not be found.
Please verify that you have entered
the server name correctly. Account:
'pop3', Server: 'smtp', Protocol:
SMTP, Port: 25, Secure(SSL): No,
Socket Error: 11001, Error Number:
0x800CCC0D
Points to note:
I am able to send and receive mails
in my outlook; Problem is only when
send mails through VBA access
application.(Means it is not a
outlook client configuration problem)
When i copy paste the Vba application to another PC, i could
successfully send emails without any
error. (means this is not a vba
access application problem)
Please help.
Either the SMTP server "smtp" is available from your second machine and not the first, or else there is some change to the mail settings and/or security when moving between the two machines.
Is your SMTP server actually called 'smtp'?
Well i got a page that sends emails and everything runs fine in the developer web server but when i publish to a IIS Server i get a FormatException when i try to send the mail....
ex.Message = "the specified string is not in the form required for an e-mail address."
the email is in this sample someone#gmail.com
Im using the "SmtpClient" and the "MailMessage" classes to send mails..
And the server runs windows server 2003
Edit:
Im using same smtp settings on the Dev Webserver as im doing in IIS.
Check that you've enabled local email relaying for the SMTP service on your Windows Server 2003 box. By 'local' I mean that applications on your local machine can use the SMTP service to relay emails - but you almost certainly don't want to allow external connections to do the same.
Make sure you don't have any invisible whitespace around your email address. For example, if you are getting the email from a database, or input control, try trimming it, like:
mail.To.Add( New MailAddress( txtEmailAddress.Text.Trim() ) )
If any one gets this problem the solution is don't use the empty constructor of MailMessage!!!!!