473,804 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending email in VB .Net via Exchange Server 2007

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.T ext
Dim strFrom As String = frmMain.txtFrom .Text
Dim strSubject As String = frmMain.txtSubj ect.Text
Dim strBody As String = frmMain.txtBody .Text
Dim mailMessage As New System.Net.Mail .MailMessage(st rFrom, strTo,
strSubject, strBody)
Dim mailClient As New
System.Net.Mail .SmtpClient("Ip AddressOfComput erRunningExchan geServer", 25)
Dim mailCredentials As New
System.Net.Netw orkCredential(" MyDomain.com\My UserName",
"ExchangeUserPa ssword", "MyDomain.c om")

mailClient.UseD efaultCredentia ls = False
mailClient.Cred entials = mailCredentials
mailClient.Deli veryMethod = Net.Mail.SmtpDe liveryMethod.Ne twork
'mailClient.Ena bleSsl = True

Try
'mailClient.Cli entCertificates .Add
((System.Securi ty.Cryptography .X509Certificat es.X509Certific ate2.CreateFrom SignedFile("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.

Jun 19 '07 #1
5 23852
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
-----------------------------------------
Jun 20 '07 #2
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.T ext
Dim strFrom As String = frmMain.txtFrom .Text
Dim strSubject As String = frmMain.txtSubj ect.Text
Dim strBody As String = frmMain.txtBody .Text
Dim mailMessage As New System.Net.Mail .MailMessage(st rFrom, strTo,
strSubject, strBody)
Dim mailClient As New
System.Net.Mail .SmtpClient("Ip AddressOfMyExch angeServer", 25)

mailClient.Cred entials = New
NetworkCredenti al("IpAddressOf MyExchangeServe r\UserName", "Password")
mailClient.Deli veryMethod = Net.Mail.SmtpDe liveryMethod.Ne twork

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
Jun 20 '07 #3
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
Jun 21 '07 #4
Thanks so much for you insight on this. It was indeed a credentials
issues.
Great!
And also thanks for posting the update! I'll put it on my FAQs page, with
reference to this posting. :-)
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
Jun 24 '07 #5
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.Smtp Client class.

SmtpClient client = new SmtpClient("smt p.server-servername.com" , 25);
MailMessage message = new MailMessage(... .);
client.Send(mes sage);

HTH.
--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------

Jun 24 '07 #6

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

Similar topics

2
3057
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 IIS, it has Exchange installed which apparantly does have SMTP capabilities but not like the default ones normally accessbile via IIS. Has anyone ever used this approach to sending emails? I'm hoping that I dont need a component or anything...
1
1639
JamieHowarth0
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 get a free Windows mail server). It's set up with Hub Transport, Client Access and Mailbox roles (I don't have an additional computer that I can run Edge Transport on - yet - and again, I know it's far from recommended to have a HT server sat...
2
2969
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 process it again next day I am using .NET 2.0 C# Need components, Ideas available. from MS or 3rd Party or Free
2
1178
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 me know. regards, chittibabu
1
3954
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 from from exchange server 2007 3. what dll's are required to work with ms exchange server 2007 using .net(C#) thanks and regarding, chittibabu c
1
2297
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
1
1633
rcollins
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 google
0
1317
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 profile name. But i wanted to read the mails of all users (configured in the exchange server). This application will run in the Exchange server machine with admin privileges. Any help here pls ?
21
7990
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 allow up to 8 characters, use the same domain always, and in a form be able to click and open an email to this customer. I have tried this in numerous ways, and I think it's occuring to me finally I can't do everything in one place. I think I might...
1
10341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
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 we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.