Greetings all,
I'm trying to send an e-mail from a Windows application thru MS Exchange
Server 2007 that is in my LAN. The setup for Exchange server is very basic,
it's running on Server 2003 R2 x64 machine. Here is the code I'm trying to
use to send the email:
Public Sub SendMail()
Dim strTo As String = frmMain.txtTo.Text
Dim strFrom As String = frmMain.txtFrom.Text
Dim strSubject As String = frmMain.txtSubject.Text
Dim strBody As String = frmMain.txtBody.Text
Dim mailMessage As New System.Net.Mail.MailMessage(strFrom, strTo,
strSubject, strBody)
Dim mailClient As New
System.Net.Mail.SmtpClient("IpAddressOfComputerRun ningExchangeServer", 25)
Dim mailCredentials As New
System.Net.NetworkCredential("MyDomain.com\MyUserN ame",
"ExchangeUserPassword", "MyDomain.com")
mailClient.UseDefaultCredentials = False
mailClient.Credentials = mailCredentials
mailClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
'mailClient.EnableSsl = True
Try
'mailClient.ClientCertificates.Add
((System.Security.Cryptography.X509Certificates.X5 09Certificate2.CreateFromSignedFile("C:\My Certificate in DER format.cer")))
mailClient.Send(mailMessage)
Catch ex As Exception
frmMain.txtInfo.Text = ex.ToString
Exit Sub
End Try
frmMain.txtInfo.Text = "Your message was sucessfully sent."
End Sub
Notice I have two lines of code commented out. If I run the the app and try
to send the email with these lines commented out I get the following
exception "The server response was 5.7.1 Unable to relay."
If I run the app with those lines not commented out, I receive the following
exception "The remote certificate is invalid according to the validation
procedure."
I need help debugging this application. I can usually get by with just the
exception but I am at my wits end here. I've read some threads about
enabling tracing thru the use of an app.config file in my project, but I'm
struggling with that as well. Any help you could provide would be much
appreciated. Please let me know if you need any additional details. Thank
you. 5 23823
Notice I have two lines of code commented out. If I run the the app and
try
to send the email with these lines commented out I get the following
exception "The server response was 5.7.1 Unable to relay."
Are you able to send the mail using the specified credentials from Outlook /
Express / Website?
The issue is that the user is not authorized to send mails, hence "Unable to
relay".
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com www.edujini-labs.com http://eduzine.edujini-labs.com
-----------------------------------------
Gaurav,
Thanks so much for you insight on this. It was indeed a credentials issues.
Two things...
1. In exchange server, I had to go to Server Configuration-->Hub
Transport-->Rerceive Connectors. Right-click on Defaut Mail and select
properties. On the Authentication tab, check off Transport Layer Security
and Exchange Users. On the Permissions Groups tab, select only Anonymous
Users and Exchange Users.
2. I also had to tweak my code. Here it is:
Public Sub SendMail()
Dim strTo As String = frmMain.txtTo.Text
Dim strFrom As String = frmMain.txtFrom.Text
Dim strSubject As String = frmMain.txtSubject.Text
Dim strBody As String = frmMain.txtBody.Text
Dim mailMessage As New System.Net.Mail.MailMessage(strFrom, strTo,
strSubject, strBody)
Dim mailClient As New
System.Net.Mail.SmtpClient("IpAddressOfMyExchangeS erver", 25)
mailClient.Credentials = New
NetworkCredential("IpAddressOfMyExchangeServer\Use rName", "Password")
mailClient.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
Try
mailClient.Send(mailMessage)
Catch ex As Exception
frmMain.txtInfo.Text = ex.ToString
Exit Sub
End Try
frmMain.txtInfo.Text = "Your message was sucessfully sent."
End Sub
Works like a charm now!! Thanks for you help.
Cheers,
Domino Effect
hi Guarav,
how can i send a email through a smtp with .net, wich is hosted by an
inetprovider? i would be very glad for some code samples
kind regards
hi Guarav,
It's Gaurav and not Guarav... ;-)
how can i send a email through a smtp with .net, wich is hosted by an
inetprovider? i would be very glad for some code samples
kind regards
Look into System.Net.SmtpClient class.
SmtpClient client = new SmtpClient("smtp.server-servername.com", 25);
MailMessage message = new MailMessage(....);
client.Send(message);
HTH.
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com www.edujini-labs.com http://eduzine.edujini-labs.com
----------------------------------------- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rob Meade |
last post by:
Hi all,
I have no knowledge of Exchange server, and have always used CDO to send
emails from ASP in the past. My problem now is that the server in question
doesn't have SMTP installed alongside...
|
by: JamieHowarth0 |
last post by:
Hi folks,
I'm running Exchange Server 2007 Beta2 on my W2K3 machine (and before you all say it, yes, I know it's not supported in production environment but it's the only way I've found so far to...
|
by: LVP |
last post by:
Hi Everyone,
I am looking to get emails from a Public Folder on our internal server using
a filter from exchange server 2007
extract attachments
tag or set the status on each email so I don't...
|
by: chelluchittibabu |
last post by:
hi,
now i need some information regarding exchange server 2007. what i want is how to connect exchange server 2007 and how to retrieve data from exchange server 2007. if any one knows pls let...
|
by: chelluchittibabu |
last post by:
hi,
pls tell me if you know regarding ms exchange server 2007. In my system i am using windows 2003. what i want is
1. how to connect ms exchange server 2007 from .net
2. how to get data...
| |
by: chelluchittibabu |
last post by:
hi,
i am working with exhange server 2007 using cdo api's. pls tell me how to retrieve appointments from exchange server 2007 using cdo in c#.
regards,
chittibabu
9945299471
|
by: rcollins |
last post by:
We have new exch 2007 servers. on a few computers, we get a logon screen when we open outlook promts for user name and password but wont connect. Need to know how to fix this. Not finding much on...
|
by: sudhivns |
last post by:
Can anybody help me with info on:
1. How to retrieve all the users configured in Exchange server
2. How to retrieve the mails of each user
I have used SMAPI to read the mails based on the...
|
by: DanicaDear |
last post by:
I've been trying to figure this out for three weeks. I've been sleeping on it. Not getting answers, just losing sleep. ;-)
In a table, I have a field COMPANY_EMAIL. In this field I want to...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |