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

Configuring SMTP for emails

P: n/a
Hi,

I'm using this code for sending emails and its working fine because I had
configured SMTP in my machine in IIS.

now I'm using machine as a server for this application. but when running the
same application from other machine the email process is not working.

so, do I have to configure and install SMTP in all client machine to get it
working!? or should it be enough just to set it in the server machine?

MailMessage objMailMsg = new MailMessage(strFrom, strTo);

objMailMsg.BodyEncoding = Encoding.UTF8;

objMailMsg.Subject = strSubject;

objMailMsg.Body = strMsg;

Attachment at = new Attachment(Server.MapPath(AttachmentPath));

objMailMsg.Attachments.Add(at);

objMailMsg.Priority = MailPriority.High;

objMailMsg.IsBodyHtml = true;

//prepare to send mail via SMTP transport

SmtpClient objSMTPClient = new SmtpClient();

objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

objSMTPClient.Send(objMailMsg);

Thanks

--
Regards,
M.Rochdi
Sep 12 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Just on the server, as ASP.Net is a server-side technology.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Mike" <Mi**@discussions.microsoft.comwrote in message
news:58**********************************@microsof t.com...
Hi,

I'm using this code for sending emails and its working fine because I had
configured SMTP in my machine in IIS.

now I'm using machine as a server for this application. but when running
the
same application from other machine the email process is not working.

so, do I have to configure and install SMTP in all client machine to get
it
working!? or should it be enough just to set it in the server machine?

MailMessage objMailMsg = new MailMessage(strFrom, strTo);

objMailMsg.BodyEncoding = Encoding.UTF8;

objMailMsg.Subject = strSubject;

objMailMsg.Body = strMsg;

Attachment at = new Attachment(Server.MapPath(AttachmentPath));

objMailMsg.Attachments.Add(at);

objMailMsg.Priority = MailPriority.High;

objMailMsg.IsBodyHtml = true;

//prepare to send mail via SMTP transport

SmtpClient objSMTPClient = new SmtpClient();

objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

objSMTPClient.Send(objMailMsg);

Thanks

--
Regards,
M.Rochdi

Sep 12 '07 #2

P: n/a
Hello,

Kevin it's right, the code to send an e-mail is sent in the server side.

Maybe there has been some changes on your SMTP server, or there is some
security restriction with the ASPNET user that runs under IIS.

I would try:

- First check if you really can send an e-mail from the server machine
now (not using .net code, using telnet, you can find this a link below).

- If you can send an e-mail using that user and password, now let's try
with the ASP .net accessing from your localhost, if you cannot try in the IIS
to use a different account (just something temporary) to ensure that is not a
permission issue.

- I would check as well if there is some restriction or rules on the SMTP
server where you rely, sometimes for instance the from must have a given a
domain name, or you shoulw login using Basic Authentication or NTLM.

More info about .net framework support to SMTP:

http://www.tipsdotnet.com/ArticleBlo...TP&PageIndex=0

Good luck
Braulio
/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------


"Mike" wrote:
Hi,

I'm using this code for sending emails and its working fine because I had
configured SMTP in my machine in IIS.

now I'm using machine as a server for this application. but when running the
same application from other machine the email process is not working.

so, do I have to configure and install SMTP in all client machine to get it
working!? or should it be enough just to set it in the server machine?

MailMessage objMailMsg = new MailMessage(strFrom, strTo);

objMailMsg.BodyEncoding = Encoding.UTF8;

objMailMsg.Subject = strSubject;

objMailMsg.Body = strMsg;

Attachment at = new Attachment(Server.MapPath(AttachmentPath));

objMailMsg.Attachments.Add(at);

objMailMsg.Priority = MailPriority.High;

objMailMsg.IsBodyHtml = true;

//prepare to send mail via SMTP transport

SmtpClient objSMTPClient = new SmtpClient();

objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

objSMTPClient.Send(objMailMsg);

Thanks

--
Regards,
M.Rochdi
Sep 12 '07 #3

P: n/a
You need to add the smtp server name, see below. from what you say I assume
that you had it working on a machine that had smtp, but now you are on a
different machine, you need to tell smtpclient what machine has smtp
remeber to add
"using System.Net.Mail;"
to the top of your page

MailMessage message = new
MailMessage("te**@here.com","so*****@there.com");
message.Subject = "Test";
message.Body = "this is the body";
SmtpClient emailClient = new SmtpClient("aSMTPserver");
emailClient.Send(message);


"Mike" <Mi**@discussions.microsoft.comwrote in message
news:58**********************************@microsof t.com...
Hi,

I'm using this code for sending emails and its working fine because I had
configured SMTP in my machine in IIS.

now I'm using machine as a server for this application. but when running
the
same application from other machine the email process is not working.

so, do I have to configure and install SMTP in all client machine to get
it
working!? or should it be enough just to set it in the server machine?

MailMessage objMailMsg = new MailMessage(strFrom, strTo);

objMailMsg.BodyEncoding = Encoding.UTF8;

objMailMsg.Subject = strSubject;

objMailMsg.Body = strMsg;

Attachment at = new Attachment(Server.MapPath(AttachmentPath));

objMailMsg.Attachments.Add(at);

objMailMsg.Priority = MailPriority.High;

objMailMsg.IsBodyHtml = true;

//prepare to send mail via SMTP transport

SmtpClient objSMTPClient = new SmtpClient();

objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

objSMTPClient.Send(objMailMsg);

Thanks

--
Regards,
M.Rochdi
Sep 12 '07 #4

P: n/a
You need to specify the host for the SMTP service :

SmtpClient objSMTPClient = new SmtpClient("mail.server.com");

or

SmtpClient objSMTPClient = new SmtpClient("111.111.111.111");
( using the IP address, instead of the SMTP host's name )


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mike" <Mi**@discussions.microsoft.comwrote in message news:58**********************************@microsof t.com...
Hi,

I'm using this code for sending emails and its working fine because I had
configured SMTP in my machine in IIS.

now I'm using machine as a server for this application. but when running the
same application from other machine the email process is not working.

so, do I have to configure and install SMTP in all client machine to get it
working!? or should it be enough just to set it in the server machine?

MailMessage objMailMsg = new MailMessage(strFrom, strTo);

objMailMsg.BodyEncoding = Encoding.UTF8;

objMailMsg.Subject = strSubject;

objMailMsg.Body = strMsg;

Attachment at = new Attachment(Server.MapPath(AttachmentPath));

objMailMsg.Attachments.Add(at);

objMailMsg.Priority = MailPriority.High;

objMailMsg.IsBodyHtml = true;

//prepare to send mail via SMTP transport

SmtpClient objSMTPClient = new SmtpClient();

objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

objSMTPClient.Send(objMailMsg);

Thanks

--
Regards,
M.Rochdi

Sep 12 '07 #5

P: n/a
Hi,

Juan T. Llibre schrieb:
You need to specify the host for the SMTP service :
SmtpClient objSMTPClient = new SmtpClient("mail.server.com");
on a side note, I would recommend not to hard-code mail server and other
settings but use .NETs built-in feature to read those from the
web.config file. Otherwise you have to recompile the application when
something changes or when you deploy your site to production.

Mike, also note that
>//prepare to send mail via SMTP transport
SmtpClient objSMTPClient = new SmtpClient();
objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
objSMTPClient.Send(objMailMsg);
this does NOT send via SMTP but writes the mail to the pickup directory
of IIS. That's all good if some mail agent on your server is configured
to pick the mails up there, otherwise you have to change the Delivery
Method to something else (I believe it's "Network") and supply
credentials for the SMTP server.

Hope this helps,

Roland
Sep 13 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.