C# .NET - sending mails from my local but am Not sending from IIS

Asked By Lalitha Kumaran on 23-May-12 07:48 AM
I am getting the following Error:

at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.CdoSysHelper.Send(String from, String to, String subject, String messageText) at System.Web.Mail.SmtpMail.Send(String from, String to, String subject, String messageText) at FleetServiceRequest_Form.MailHelper.SendMailMessage(String from, String to, String bcc, String cc, String subject, String body) in D:\Common\Big Test Environment\FleetServiceRequest\MailHelper.cs:line 79 at FleetServiceRequest_Form._Default.Save() in D:\Common\Big Test Environment\FleetServiceRequest\FleetService.aspx.cs:line 427


My Code:

{

System.Web.Mail.

MailMessage mMailMessage = new System.Web.Mail.MailMessage();

mMailMessage.From = from;

mMailMessage.To = to;


if ((bcc != null) && (bcc != string.Empty))

{

mMailMessage.Bcc = bcc;

}


if ((cc != null) && (cc != string.Empty))

{

mMailMessage.Cc = cc;

}

mMailMessage.Subject = subject;

mMailMessage.Body = body;


mMailMessage.BodyFormat = System.Web.Mail.

MailFormat.Html;

mMailMessage.Priority = System.Web.Mail.

MailPriority.High;

System.Net.

NetworkCredential basiccredential = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["mailUID"], ConfigurationSettings.AppSettings["mailPWD"], ConfigurationSettings.AppSettings["mailhost"]);

System.Web.Mail.

SmtpMail.SmtpServer = "mail.bigholding.com";


System.Web.Mail.

SmtpMail.Send("mailid", "mailid", "Test", "Test");




// SmtpMail.Send(mMailMessage);




}

Jitendra Faye replied to Lalitha Kumaran on 23-May-12 08:02 AM
TRy like this-

For sending mail you have to use MailMessage Class.

you can include image in message body-

follow this code

protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtUsername.Text);
// Recipient e-mail address.
Msg.To.Add(txtTo.Text);
Msg.Subject = txtSubject.Text;
// File Upload path
String FileName = fileUpload1.PostedFile.FileName;
string mailbody = txtBody.Text + "<br/><img src=cid:companylogo>";
LinkedResource myimage = new LinkedResource(FileName);
// Create HTML view
AlternateView htmlMail = AlternateView.CreateAlternateViewFromString(mailbody, null, "text/html");
// Set ContentId property. Value of ContentId property must be the same as
// the src attribute of image tag in email body. 
myimage.ContentId = "companylogo";
htmlMail.LinkedResources.Add(myimage);
Msg.AlternateViews.Add(htmlMail);
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials=new System.Net.NetworkCredential(txtUsername.Text,txtpwd.Text);
smtp.EnableSsl = true;
smtp.Send(Msg);
Msg = null;
Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');if(alert){ window.location='SendMail.aspx';}</script>");
}
catch (Exception ex)
{

}
}



Lalitha Kumaran replied to Jitendra Faye on 23-May-12 08:06 AM
I tried with all the Options.My application sends mail from my development machine.But, when i deployed it into IIS am getting these errors.