SmtpMail.Send() No Error but no Email either.

S

supz

Hi,

I use the standard code given below to send an email from an ASP.NET
web form. The code executes fine but no Email is sent. All emails get
queued in the Inetpub mail queue.

I'm using my local default SMTP Server and my from address is a valid
Yahoo/Hotmail address. I have configures the local SMTP Server to allow
the IP Address 127.0.0.1.

Could this be because yahoo/hotmail servers need authentication?

Here's the code I use.

private void SendSimpleMail()
{

MailMessage objEmail = New MailMessage();
objEmail.From = "(e-mail address removed)";
objEmail.To = "(e-mail address removed)";
objEmail.Subject = "Test Mail";
objEmail.Body = "Test Mail - Body";
SmtpMail.SmtpServer = "127.0.0.1";


SmtpMail.Send(objEmail);

}


Any idea what could be wrong or what I need to do to send a simple
email from ASP.NET? Any help would be appreaciated.

Regards,
supz
 
J

John Timney \( MVP \)

You may have forgotton to set up your smart host settings in smtp under iis.
This tells IIS how to route the SMTP message, in effect who to pass it to
for onward delivery.
 
S

supz

Thanks for your prompt replies. This might be a stupid quuestion, but
do I really need to set up the smart host settings? I read somewhere
that the local SMTP server sends the mail to the relay server which
will send the email to the recipient. If I send using a "yahoo" address
in the "from" field, is it the responsibilty of the Yahoo server to
deliver the mail?
 
J

Juan T. Llibre

re:
If I send using a "yahoo" address in the "from" field,
is it the responsibilty of the Yahoo server to deliver the mail?

No, it is not.
The mail will be delivered to the "TO:" address by your SMTP server.

re:
do I really need to set up the smart host settings?

You don't have to use a smart host, although sometimes it's better to use one.
Not all the time, though.

re:
I read somewhere that the local SMTP server sends the mail
to the relay server which will send the email to the recipient.

Only if you use an external SMPT server.
If you use your own smtp server, *it* will send the mail.

The thing is that you must configure your smtp server so it:

1. can be found by the .Net Framework
2. allows mail relay only from certain IPs or machines.
Otherwise, anyubody can use *your* smtp server to send *their* mail.
Spammers would love it if you opened your smtp server so the could send their spam.

Have you set the "Connection control" and "Relay Restrictions" ?
( in the "Access" tab...after opening the smtp server's properties in the IIS Manager ).

This is extremely important.

They should be *both* set to your IP address.

Also, in the "Delivery" tab, in the "Advanced" button,
you can, optionally, set the domain name, if you have one.

Then, in your code, assign your machine name or domain name to the smtp client :

For ASP.NET 2.0 :
Dim client As New SmtpClient("yourmachinename")
client.Send(mail)

For ASP.NET 1.1 :
System.Web.Mail.SmtpMail.SmtpServer = "your machine name or your domain name"
System.Web.Mail.SmtpMail.Send(mail)
 
J

John Timney \( MVP \)

You can try to replace the smtp device

SmtpMail.SmtpServer = "mail.yahoo.co.uk";

It migth still fail though, yahoo probably requires a username and password
to forward mail through it and you might need to use a thrid party component
http://www.aspnetemail.com/

or if your using .net 1.1 or above

private void Page_Load(object sender, System.EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To = "(e-mail address removed)";
mail.From = "(e-mail address removed)";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
"my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
"super_secret"); //set your password here

SmtpMail.SmtpServer = "mail.mycompany.com"; //your real server goes here
SmtpMail.Send( mail );
}
taken from http://www.systemwebmail.com/faq/3.8.aspx
 
K

KMA

Juan,

Can you explain this a bit more.

I've just made a contact page for my site to allow people to write a
message. Then the site sends the message via email to my private address.
Now, it all works fine, but I've got a nagging feeling because it works from
both my local test machine and the shared host. But I never specify any
password, and I'm worrying that anybody could send mail. since I'm on shared
hosting I don't get access to IIS. I thought at first that it would only
work on the host (some kind of permission for the ASP.NET worker process)
but it works local too. I'm worried. What can I do?

BTW the code is lifted straight from many examples from the web and is
almost identical to what you've posted below. (1.1 version).

Thankyou.
 
S

sloan

See my blog entry:
http://spaces.msn.com/sholliday/
2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)


I have
No(authentication)
Basic
and
SSL


gmail is the example I use....you might want to get an gmail account and use
it,,if the yahoo keeps failing.
 
S

sloan

PS

If you get the yahoo settings worked out...with my code from my blog.
Could you post a reply here...and a comment at the blog on which settings
you used.

Thanks...
 
J

Juan T. Llibre

re:
I'm worrying that anybody could send mail

In fact, anybody who can view that page will be able to send mail to you.

If you've hard-coded the address you need not worry,
except for the occasional spambot which will send you spam.

If you haven't hard-coded the address
( if you use a textbox for the user to write in the email address )
then anybody could send an email to anybody else, and you could
be the victim of an automated spam-sending scheme.
 
K

KMA

Juan,

Thanks for the quick reply.

Just to clarify, *my* ASP.NET program has the recipient address hard coded
to me at (e-mail address removed), so no problem there. And of course anyone
can spam me through the contact form, or indeed simply by putting
(e-mail address removed) etc. This much is clear and unavoidable.

But, from what I can tell, if *you* wrote a test ASP.NET app, and copied and
pasted my code from my project (or even if you knew the domain) then you
could spam whoever you want through my shared hosts SMTP server. The problem
is I can't find where the security is set. Surely they don't just leave this
kind of hole open, do they?

Hopefully I've explained myself better now.

Thanks for the quick reply.
 
J

Juan T. Llibre

re:
But, from what I can tell, if *you* wrote a test ASP.NET app, and copied and pasted my code from
my project (or even if you knew the domain) then you could spam whoever you want through my shared
hosts SMTP server.

Not really. See below.

re:
The problem is I can't find where the security is set. Surely they don't just leave this kind of
hole open, do they?

Your SMTP server should have its "Relay Restrictions" set.

If you set the relay restrictions to only allow traffic from the same machine IP
as your smtp server, your smtp server can't be used by external spammers.

In the IIS Manager, after opening the smtp server's properties,
you'll find the "Relay Restrictions" dialog in the "Access" tab.

If you don't have access to the IIS Manager, ask your provider
about the Relay restrictions they have in place.
 
K

KMA

Juan T. Llibre said:
re:

Not really. See below.

re:

Your SMTP server should have its "Relay Restrictions" set.

If you set the relay restrictions to only allow traffic from the same
machine IP
as your smtp server, your smtp server can't be used by external spammers.

In the IIS Manager, after opening the smtp server's properties,
you'll find the "Relay Restrictions" dialog in the "Access" tab.

If you don't have access to the IIS Manager, ask your provider
about the Relay restrictions they have in place.

Thanks Juan.

I'm definitely going to do this. I could understand if I were unable to send
locally while testing. Hopefully the local test only works because I'm
already "hidden" logged in through my email client. I'll have to
investigate. Thanks for pointing me down the right road. At least I can
explain the problem to the shared host easier now.
 
K

KMA

Juan,

Just an update. It appears that, locally at least, I can only forward to
addresses in the same (my) domain. At least this puts my mind at rest
regarding people spamming others through me. I could still get loads of
spam, but then again I get loads anyway.

Cheers.
 
G

Guest

hi all,

i am getting the same problem but in windows application (vb.net). whenever
i try to send email from (e-mail address removed) to (e-mail address removed) it
works fine but if i change address TO field with valid yahoo / hotmail the
message going in the queue folder.

i am planning to develop an email sending application that sends GCC
investment oppertunies / GCC Market Review / Other Market Results to our
90,000 subscribers.
any suggestion would be greatly appricated :)
 

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

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top