Configuring SMTP for emails

G

Guest

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
 
G

Guest

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/ArticleBlog.aspx?KWID=45&Area=SMTP&PageIndex=0

Good luck
Braulio


/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------
 
T

ThatsIT.net.au

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("(e-mail address removed)","(e-mail address removed)");
message.Subject = "Test";
message.Body = "this is the body";
SmtpClient emailClient = new SmtpClient("aSMTPserver");
emailClient.Send(message);
 
J

Juan T. Llibre

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/
======================================
 
R

Roland Dick

Hi,
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 thatthis 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
 

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