Email Programming using System.Web.Mail

E

Ed Bitzer

I have been able using the namespace System.Web.Mail and its method
Smtp.mail.send to mail simple text messages to a small group within
our 55 and older community. I need help expanding the programs
capabilities. Searching this forum I did not find any related
information so if I have chosen poorly, I would appreciate a
suggestion of a more appropriate dotnet forum.

Now what I wish is the ability to send bcc's rather than to: (would be
sending to all 250 residents and would have to send in groups of 50 as
required by Comcast to curtail spammers) and also wonder if this
namespace handles base64 encoding so that I can send a pdf attachment.
Appreciate,

Ed
 
R

rowe_newsgroups

I have been able using the namespace System.Web.Mail and its method
Smtp.mail.send to mail simple text messages to a small group within
our 55 and older community. I need help expanding the programs
capabilities. Searching this forum I did not find any related
information so if I have chosen poorly, I would appreciate a
suggestion of a more appropriate dotnet forum.

Now what I wish is the ability to send bcc's rather than to: (would be
sending to all 250 residents and would have to send in groups of 50 as
required by Comcast to curtail spammers) and also wonder if this
namespace handles base64 encoding so that I can send a pdf attachment.
Appreciate,

Ed

Though it might not help with encoding (not sure) two excellent sites
you need to check out are:

http://www.systemwebmail.com/

And

http://www.systemnetmail.com/

IMO if you are using 2.0 or higher you should be using System.Net.Mail

Thanks,

Seth Rowe [MVP]
 
T

Thomas Weise

Ed,

This is how I attach files to eMails sent via System.Net.Mail:
Private Sub AddAttachment(ByRef message As MailMessage, ByVal sFile As
String)
Dim attFile As Attachment
Dim disposition As ContentDisposition

attFile = New Attachment(sFile)
disposition = attFile.ContentDisposition
disposition.CreationDate = System.IO.File.GetCreationTime(sFile)
disposition.ModificationDate =
System.IO.File.GetLastWriteTime(sFile)
disposition.ReadDate = System.IO.File.GetLastAccessTime(sFile)
message.Attachments.Add(attFile)
End Sub

The MailMessage object does have a Bcc property, so you can add Bcc adresses
(don't know how many):
Dim adrBcc As MailAddress

adrBcc = New MailAddress("(e-mail address removed)")
message.Bcc.Add(adrBcc)

adrBcc = New MailAddress("(e-mail address removed)")
message.Bcc.Add(adrBcc)
...

Hope this helps,
Thomas
 
T

Thomas Weise

I should have emphasized:
I'm using System.Net.Mail instead of System.Web.Mail (NET 2.0)
The types I'm using (MailMessage, Attachment) are part of that namespace.
 
E

Ed Bitzer

rowe_newsgroups said:
Though it might not help with encoding (not sure) two excellent
sites
you need to check out are:

http://www.systemwebmail.com/

And

http://www.systemnetmail.com/

IMO if you are using 2.0 or higher you should be using
System.Net.Mail

Thanks,

Seth Rowe [MVP]


Seith and Patrice too,



I have waded my way through all the references gave and digested
sufficiently to create a prototype that sends an email To: somebody,
with Bcc's to several others and can handle one or more pdf
attachments encoded with Base64 - and it works<g>. Obviously you guys
gave me excellent directions. I do have one more questions and that
is how is this stuff getting to the recipients. I am sending from my
home. I am providing system.web.mail with no information about my
ISP. Does my program act as a Server and do its own thing looking up
the DNS information for each of the recipients ISP's? When I use
commercial software such as Thunderbird or OE I must spell out the
smtp servicer and provide a username and password.



Ed
 
E

Ed Bitzer

Thomas Weise said:
I should have emphasized:
I'm using System.Net.Mail instead of System.Web.Mail (NET 2.0)
The types I'm using (MailMessage, Attachment) are part of that
namespace.

Thomas,



The syntax is quite different than my older version of VB.Net (203)
where I am using System.Net.Mail (but of course requires the same
information); however, I was successful as you may have noticed in the
note I just wrote to Seth and Patrice. I asked them how this was
getting out of my home computer because I know if we send to our 250
or so residence in this 55 and older community (and we are sending out
announcements daily) we must send them to less than 100 addresses per
connection. This is a limitation imposed by Comcast, our ISP, to
limit spam (I was going to say eliminate, but they certainly have not
figured out a solution there). If my mail program is being sent
through their server, I can easily fix the program so that it
connects, sends 100, disconnects, reconnects and sends another 100.
This is going to be a big time saver. Now I use to be the guy who
processed all the mail requests from our community but I recently
managed to pawn the job off on another retired guy. Maybe I can get a
free lunch out of this program<g>



Ed
 
K

Kevin S Gallagher

I can understand the Comcast restriction, our group went thru this and
decided to simply buy into a service rather then coding and maintain it.
Sometimes using a service is better then spending time coding.
 
E

Ed Bitzer

Kevin S Gallagher said:
I can understand the Comcast restriction, our group went thru this
and decided to simply buy into a service rather then coding and
maintain it. Sometimes using a service is better then spending time
coding.


Kevin,



I am retired, this is my hobby and I already have the program working.
My question is outside the box of coding but how does my VB.Net
program actually send thee messages? I do not believe they are going
thru my Comcast SMTP account.



Ed
 
S

Stephany Young

Time for everyone to get on the same page I think.

The first thing that you need to confirm is that you are, in fact, using an
instance of the System.Net.Mail.SmtpClient class to senn your emails.

If you're not then it's all back to square one.

If you are then it would be interesting to see how you instantiate the
instance.

'The book' says that if you do not supply a target 'host', either in the
constructor or by setting the Host property then the instance will use
whatever is specified in your application or machine configuration files.
(It will 'look' in the application configuration first but if that doesn't
specify the appropriate information then it will fall back to the machine
configuration file.) While it doesn't say so in so many words, it implies
that it doesn't 'look' anywhere else, therefore I would expect that, if you
don't specify it and it isn't specified in either of the configuration
files, an exception would be thrown when you call the Send method.

I have just confirmed this by using:

Dim _client As New SmtpClient

_client.Send(New MailMessage("fromaddress", "toaddress", "Test", "Test"))

It results in an InvalidOperationException with the message 'The SMTP host
was not specified.'.

The moment I specify a valid server then it works:

Dim _client As New SmtpClient("server")

_client.Send(New MailMessage("fromaddress", "toaddress", "Test", "Test"))



If you are definitely NOT specifying a 'host' in your code then that means
that you MUST have a 'host' specified in one or more of your config files.
All it is now, is a matter of you looking to see what it is. I know of no
automatic mechanism that will put such information in the configuration
files (but that doesn't mean such a mechanism doesn't exist).


The SmtpClient class is, as it's name suggests, a 'client' object and not a
'server' object. It will only connect to an 'up-line' SMTP server. If the
recipient's 'mailbox' is not directly served by that server then the message
will be relayed on to the appropriate server.
 
E

Ed Bitzer

Stephany Young said:
Time for everyone to get on the same page I think.

The first thing that you need to confirm is that you are, in fact,
using an instance of the System.Net.Mail.SmtpClient class to senn
your emails.

If you're not then it's all back to square one.

If you are then it would be interesting to see how you instantiate
the instance.

'The book' says that if you do not supply a target 'host', either in
the constructor or by setting the Host property then the instance
will use whatever is specified in your application or machine
configuration files. (It will 'look' in the application
configuration first but if that doesn't specify the appropriate
information then it will fall back to the machine configuration
file.) While it doesn't say so in so many words, it implies that it
doesn't 'look' anywhere else, therefore I would expect that, if you
don't specify it and it isn't specified in either of the
configuration files, an exception would be thrown when you call the
Send method.

I have just confirmed this by using:

Dim _client As New SmtpClient

_client.Send(New MailMessage("fromaddress", "toaddress", "Test",
"Test"))

It results in an InvalidOperationException with the message 'The
SMTP host was not specified.'.

The moment I specify a valid server then it works:

Dim _client As New SmtpClient("server")

_client.Send(New MailMessage("fromaddress", "toaddress", "Test",
"Test"))



If you are definitely NOT specifying a 'host' in your code then that
means that you MUST have a 'host' specified in one or more of your
config files. All it is now, is a matter of you looking to see what
it is. I know of no automatic mechanism that will put such
information in the configuration files (but that doesn't mean such a
mechanism doesn't exist).


The SmtpClient class is, as it's name suggests, a 'client' object
and not a 'server' object. It will only connect to an 'up-line' SMTP
server. If the recipient's 'mailbox' is not directly served by that
server then the message will be relayed on to the appropriate
server.


Stephany,


I just want you and the others to know how much I appreciate your

efforts on my behalf. I need to digest your latest comments but first

I want all to know that I have a prototype working thanks to the
references given, especially the excellent summary of threads provided
at www.systemwebmail.com. (I am using Net 1.1 and

therefore System.Web.Mail) If I do not provide an SMTP server the
program works (my simple minded understanding is that VB.Net has a
basic SMTP code within but better yet I can specify my local ISP,
provide the username and password. If I understand correctly by this
is safer avoiding any reflection that my ISP is providing an open
relay.


Ed
 
S

Stephany Young

With System.Web.Mail, (1.1), the book for the SmtpMail class says that if
you do not specify a value for SmtpServer then it uses the local SMTP
server.

If you are not explicitly specifying a value for SmtpServer then you MUST
some form of SMTP server running on the machine. You may not necessarily
realise that you have such a server running, but you would not be able to
send a message via the SmtpMail class without it.

To clarify a point, VB.Net does NOT have any form of SMTP within it and does
no 'magic' on your behalf. You must explicitly use the SMTP class(es)
provided by the .NET Framework, which are not actually part of Vb.Net per
se.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top