By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 1,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

Exception Thrown please check code

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.