473,385 Members | 1,640 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,385 software developers and data experts.

Exception Thrown please check code

System.InvalidOperationException was caught
Message="A from address must be specified."

Public Shared Sub sendEmail(ByVal fromAddy As String, ByVal toAddy As
String, ByVal subject As String, ByVal body As String)
Try
Dim fromAddress As New
System.Net.Mail.MailAddress(fromAddy)
Dim toAddress As New System.Net.Mail.MailAddress(toAddy)
Dim msg As New System.Net.Mail.MailMessage
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient()
mailSender.Host = "mailgate.nau.edu"
mailSender.Send(msg)
Catch ex As Exception
lblError = ex.ToString
End Try
End Sub

I have stepped through line by line and fromAddress does have a value
however I am still gettig the exception?

Feb 14 '07 #1
8 2872
Yes, at the point that you 'send' the message, fromAddress 'does have a
value', but what are you doing with fromAddress?

Once you've figured that out you have the same issue with toAddress.
"AZNewsh" <gn@dana.ucc.nau.eduwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
System.InvalidOperationException was caught
Message="A from address must be specified."

Public Shared Sub sendEmail(ByVal fromAddy As String, ByVal toAddy As
String, ByVal subject As String, ByVal body As String)
Try
Dim fromAddress As New
System.Net.Mail.MailAddress(fromAddy)
Dim toAddress As New System.Net.Mail.MailAddress(toAddy)
Dim msg As New System.Net.Mail.MailMessage
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient()
mailSender.Host = "mailgate.nau.edu"
mailSender.Send(msg)
Catch ex As Exception
lblError = ex.ToString
End Try
End Sub

I have stepped through line by line and fromAddress does have a value
however I am still gettig the exception?
Feb 14 '07 #2
AZNewsh wrote:
System.InvalidOperationException was caught
Message="A from address must be specified."

Public Shared Sub sendEmail(ByVal fromAddy As String, ByVal toAddy As
String, ByVal subject As String, ByVal body As String)
Try
Dim fromAddress As New
System.Net.Mail.MailAddress(fromAddy)
Dim toAddress As New System.Net.Mail.MailAddress(toAddy)
Dim msg As New System.Net.Mail.MailMessage
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient()
mailSender.Host = "mailgate.nau.edu"
mailSender.Send(msg)
Catch ex As Exception
lblError = ex.ToString
End Try
End Sub

I have stepped through line by line and fromAddress does have a value
however I am still gettig the exception?
You are not assigning the toAddress or the fromAddress to the msg.
Feb 14 '07 #3
On Feb 14, 1:33 pm, CodeMonkey <spamm...@suck.comwrote:
AZNewsh wrote:
System.InvalidOperationException was caught
Message="A from address must be specified."
Public Shared Sub sendEmail(ByVal fromAddy As String, ByVal toAddy As
String, ByVal subject As String, ByVal body As String)
Try
Dim fromAddress As New
System.Net.Mail.MailAddress(fromAddy)
Dim toAddress As New System.Net.Mail.MailAddress(toAddy)
Dim msg As New System.Net.Mail.MailMessage
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient()
mailSender.Host = "mailgate.nau.edu"
mailSender.Send(msg)
Catch ex As Exception
lblError = ex.ToString
End Try
End Sub
I have stepped through line by line and fromAddress does have a value
however I am still gettig the exception?

You are not assigning the toAddress or the fromAddress to the msg.- Hide quoted text -

- Show quoted text -
Duh, that's what you get for copy and pasting old code, not sure why
that was missing - anyway, I added:

msg.From = fromAddress
msg.To = toAddress

now I am getting an error saying msg.To is read only in the editor,
however no problem with msg.from

Feb 14 '07 #4
AZNewsh wrote:
On Feb 14, 1:33 pm, CodeMonkey <spamm...@suck.comwrote:
>AZNewsh wrote:
>>System.InvalidOperationException was caught
Message="A from address must be specified."
Public Shared Sub sendEmail(ByVal fromAddy As String, ByVal toAddy As
String, ByVal subject As String, ByVal body As String)
Try
Dim fromAddress As New
System.Net.Mail.MailAddress(fromAddy)
Dim toAddress As New System.Net.Mail.MailAddress(toAddy)
Dim msg As New System.Net.Mail.MailMessage
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient()
mailSender.Host = "mailgate.nau.edu"
mailSender.Send(msg)
Catch ex As Exception
lblError = ex.ToString
End Try
End Sub
I have stepped through line by line and fromAddress does have a value
however I am still gettig the exception?
You are not assigning the toAddress or the fromAddress to the msg.- Hide quoted text -

- Show quoted text -

Duh, that's what you get for copy and pasting old code, not sure why
that was missing - anyway, I added:

msg.From = fromAddress
msg.To = toAddress

now I am getting an error saying msg.To is read only in the editor,
however no problem with msg.from
That's because To is a collection of mail addresses. You can send to
multiple addresses, but you can only send from one address.
Feb 14 '07 #5
On Feb 14, 1:53 pm, CodeMonkey <spamm...@suck.comwrote:
AZNewsh wrote:
On Feb 14, 1:33 pm, CodeMonkey <spamm...@suck.comwrote:
AZNewsh wrote:
System.InvalidOperationException was caught
Message="A from address must be specified."
Public Shared Sub sendEmail(ByVal fromAddy As String, ByVal toAddy As
String, ByVal subject As String, ByVal body As String)
Try
Dim fromAddress As New
System.Net.Mail.MailAddress(fromAddy)
Dim toAddress As New System.Net.Mail.MailAddress(toAddy)
Dim msg As New System.Net.Mail.MailMessage
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient()
mailSender.Host = "mailgate.nau.edu"
mailSender.Send(msg)
Catch ex As Exception
lblError = ex.ToString
End Try
End Sub
I have stepped through line by line and fromAddress does have a value
however I am still gettig the exception?
You are not assigning the toAddress or the fromAddress to the msg.- Hide quoted text -
- Show quoted text -
Duh, that's what you get for copy and pasting old code, not sure why
that was missing - anyway, I added:
msg.From = fromAddress
msg.To = toAddress
now I am getting an error saying msg.To is read only in the editor,
however no problem with msg.from

That's because To is a collection of mail addresses. You can send to
multiple addresses, but you can only send from one address.- Hide quoted text -

- Show quoted text -
I am feeling pretty silly now but still don't follow:

msg.From = fromAddress does contain only one address and is not
causing an error, however
msg.To = toAddress does contain several addresses in the form:

fromAddy =
"th**********@mail.com;an*****@mail.com;yet.an**** *@mail.com"

I don't understand why I get a read only error when I try to assign
these addresses to msg.To or what I should do instead.

By the way thank you both for your quick and polite replies

Feb 14 '07 #6
AZNewsh wrote:
I am feeling pretty silly now but still don't follow:

msg.From = fromAddress does contain only one address and is not
causing an error, however
msg.To = toAddress does contain several addresses in the form:

fromAddy =
"th**********@mail.com;an*****@mail.com;yet.an**** *@mail.com"

I don't understand why I get a read only error when I try to assign
these addresses to msg.To or what I should do instead.

By the way thank you both for your quick and polite replies
Well, the From is a single mail address, so you can assign it by doing
msg.From = fromAddress. That is fine... With To being a collection, you
will have to do msg.To.Add(toAddress) in order to add to that collection.
Feb 14 '07 #7
On Feb 14, 2:06 pm, CodeMonkey <spamm...@suck.comwrote:
AZNewsh wrote:
I am feeling pretty silly now but still don't follow:
msg.From = fromAddress does contain only one address and is not
causing an error, however
msg.To = toAddress does contain several addresses in the form:
fromAddy =
"this.addr...@mail.com;anot...@mail.com;yet.anot.. .@mail.com"
I don't understand why I get a read only error when I try to assign
these addresses to msg.To or what I should do instead.
By the way thank you both for your quick and polite replies

Well, the From is a single mail address, so you can assign it by doing
msg.From = fromAddress. That is fine... With To being a collection, you
will have to do msg.To.Add(toAddress) in order to add to that collection.
Perfect!!
Site is up and running, thanks for your help in finding a quick
solution.

Feb 14 '07 #8
here is a good site

http://www.systemnetmail.com/
AZNewsh wrote:
>System.InvalidOperationException was caught
Message="A from address must be specified."
Public Shared Sub sendEmail(ByVal fromAddy As String, ByVal toAddy As
String, ByVal subject As String, ByVal body As String)
Try
Dim fromAddress As New
System.Net.Mail.MailAddress(fromAddy)
Dim toAddress As New System.Net.Mail.MailAddress(toAddy)
Dim msg As New System.Net.Mail.MailMessage
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient()
mailSender.Host = "mailgate.nau.edu"
mailSender.Send(msg)
Catch ex As Exception
lblError = ex.ToString
End Try
End Sub
I have stepped through line by line and fromAddress does have a value
however I am still gettig the exception?
You are not assigning the toAddress or the fromAddress to the msg.

Feb 14 '07 #9

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

Similar topics

10
by: Gary.Hu | last post by:
I was trying to catch the Arithmetic exception, unsuccessfully. try{ int a = 0, b = 9; b = b / a; }catch(...){ cout << "arithmetic exception was catched!" << endl; } After ran the program,...
6
by: Páll Ólafsson | last post by:
Hi I have a problem with the Microsoft.ApplicationBlocks.ExceptionManagement? I can't get it to work in RELEASE mode? If I run the project in debug mode the block works fine but when I run the...
4
by: Bhavya Shah | last post by:
Hello, I am facing a very strange problem in my application. I have a form on which I select a path. I open the FolderBrowserDialog for path selection. Once the path is selected I press a button...
4
by: Anders Borum | last post by:
Hello! I am working on improving my threading skills and came across a question. When working with the ReaderWriterLock class, I am getting an unhandled exception if I acquire a WriterLock with...
3
by: Gary | last post by:
I'm in the application_error event. I want to know which aspx experienced the exception. Is there any easy way? Thanks, G
19
by: Diego F. | last post by:
I think I'll never come across that error. It happens when running code from a DLL that tries to write to disk. I added permissions in the project folder, the wwwroot and in IIS to NETWORK_SERVICE...
132
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid...
11
by: Don | last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a way to get more detailed information about an error other than Exception.Message or Exception.ToString? For example,...
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.