473,416 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Sending Email using Exchange server

I'm trying to create a simple form that sends an email using my
company's exchange server. I'm using the System.Net.Mail Namespace of
the .net framework 2.0.
I've googled everywhere and i think my code is ok, however i keep
getting a "A connection attempt failed because the connected party did
not properly respond after a period of time, or established connection
failed because connected host has failed to respond" error every time.
Any one has any ideas why this is happening?

Imports System.Net.Mail
'Imports System.Web.Mail

Public Class frmsendmail
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents txtServidor As System.Windows.Forms.TextBox
Friend WithEvents CmdEnviar As System.Windows.Forms.Button
Friend WithEvents txtDe As System.Windows.Forms.TextBox
Friend WithEvents txtPara As System.Windows.Forms.TextBox
Friend WithEvents txtAssunto As System.Windows.Forms.TextBox
Friend WithEvents txtEmail As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()Private Sub
InitializeComponent()
Me.txtServidor = New System.Windows.Forms.TextBox
Me.CmdEnviar = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.txtDe = New System.Windows.Forms.TextBox
Me.txtPara = New System.Windows.Forms.TextBox
Me.txtAssunto = New System.Windows.Forms.TextBox
Me.txtEmail = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'txtServidor
'
Me.txtServidor.Location = New System.Drawing.Point(136, 56)
Me.txtServidor.Name = "txtServidor"
Me.txtServidor.Size = New System.Drawing.Size(168, 20)
Me.txtServidor.TabIndex = 0
Me.txtServidor.Text = ""
Me.txtServidor.Visible = False
'
'CmdEnviar
'
Me.CmdEnviar.Location = New System.Drawing.Point(344, 296)
Me.CmdEnviar.Name = "CmdEnviar"
Me.CmdEnviar.TabIndex = 1
Me.CmdEnviar.Text = "Enviar"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(72, 56)
Me.Label1.Name = "Label1"
Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label1.Size = New System.Drawing.Size(48, 23)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Servidor:"
Me.Label1.Visible = False
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(96, 96)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(32, 23)
Me.Label2.TabIndex = 3
Me.Label2.Text = "De:"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(88, 136)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(40, 23)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Para:"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(80, 168)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(48, 23)
Me.Label4.TabIndex = 5
Me.Label4.Text = "Assunto:"
'
'txtDe
'
Me.txtDe.Location = New System.Drawing.Point(136, 96)
Me.txtDe.Name = "txtDe"
Me.txtDe.Size = New System.Drawing.Size(168, 20)
Me.txtDe.TabIndex = 6
Me.txtDe.Text = ""
'
'txtPara
'
Me.txtPara.Location = New System.Drawing.Point(136, 136)
Me.txtPara.Name = "txtPara"
Me.txtPara.Size = New System.Drawing.Size(168, 20)
Me.txtPara.TabIndex = 7
Me.txtPara.Text = ""
'
'txtAssunto
'
Me.txtAssunto.Location = New System.Drawing.Point(136, 176)
Me.txtAssunto.Name = "txtAssunto"
Me.txtAssunto.Size = New System.Drawing.Size(168, 20)
Me.txtAssunto.TabIndex = 8
Me.txtAssunto.Text = ""
'
'txtEmail
'
Me.txtEmail.Location = New System.Drawing.Point(40, 224)
Me.txtEmail.Multiline = True
Me.txtEmail.Name = "txtEmail"
Me.txtEmail.Size = New System.Drawing.Size(264, 88)
Me.txtEmail.TabIndex = 9
Me.txtEmail.Text = ""
'
'frmsendmail
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(456, 390)
Me.Controls.Add(Me.txtEmail)
Me.Controls.Add(Me.txtAssunto)
Me.Controls.Add(Me.txtPara)
Me.Controls.Add(Me.txtDe)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.CmdEnviar)
Me.Controls.Add(Me.txtServidor)
Me.Name = "frmsendmail"
Me.Text = "sendmail"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub CmdEnviar_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CmdEnviar.Click
Dim oEmail As New MailMessage
Dim oSmtpServer As New Net.Mail.SmtpClient()

Try
With oEmail
.From = New MailAddress(txtDe.Text)
.To.Add(txtPara.Text)
.IsBodyHtml = False
.Subject = Me.txtAssunto.Text
.Body = Me.txtEmail.Text
.Priority = MailPriority.High

End With

oSmtpServer.Host = "my.exchange.server"
oSmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network
oSmtpServer.Port = 25
oSmtpServer.Timeout = 900000
oSmtpServer.Credentials =
Net.CredentialCache.DefaultNetworkCredentials

oSmtpServer.Send(oEmail)

MsgBox("Email was sent", MsgBoxStyle.Information, "Info:")

Catch ex As Exception

MsgBox(ex.InnerException.InnerException.Message,
MsgBoxStyle.Exclamation, ex.Message)

Finally

oEmail = Nothing
oSmtpServer = Nothing

End Try

End Sub

End Class

Apr 17 '07 #1
0 2745

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Sven Templin | last post by:
Hello all, our configuration is as following described: - OS: Windows 2000 - Apache server 1.3 - Php 3.8 - MS outlook client 2000 _and_ no SMTP server available in the whole intranet.
3
by: martin smith | last post by:
Here's the scenario. I'm currently using cdosys/asp to send mail to our SMTP server. We use a product called MailFilter to check for SPAM. It doesn't work very well. If MailFilter isn't working...
17
by: Bonj | last post by:
Right guys. (I would like a solution to this in VB6 as this is what our needy app is written in, but any solutions that involve .NET would be much appreciated likewise as I could instantiate...
2
by: Gaz | last post by:
Hi all I am currently trying to send and email via exchange except I'm having a nightmare getting it working, you'd think this would be pertty simple wouldn't you? I have added a reference to...
2
by: Jim in Arizona | last post by:
I've made an application that is a computer problems (tickets) system. The employee goes to a web page and posts the comptuer problem they're having. Then, the IS staff goes to another webpage...
8
by: Frank | last post by:
I think I've confused myself completely here :-) I have used System.Web.Mail, but am not sure if this works with Exchange Server 5.5. I asked the client if they're email server supported SMTP, and...
9
by: B-Dog | last post by:
I've built a small app that sends mail through our ISP's SMTP server but when I try to send through my local exchange server I get CDO error. Does webmail use SMTP or does it strictly rely on...
1
by: Gilbert Cheung | last post by:
Hello. I am writing a website for my company. There is a sign-up form that requires us to send a confirmation email to our customer. Our company uses Exchange Server 2000 as our mail server. We...
3
by: John | last post by:
Hi I have a vb.net win form app that runs on a MS Small Business Server 2003 (windows 20003 server + ISA 2000 + exchange 2000). My question is how can I send external emails from the app via...
14
by: sridhar | last post by:
iam having user account on an exchangeserver. with that can i send an email using python? if iam using the following code iam getting error fromAddress = 'sridhar_kasturi@satyam.com'...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.