Sending Email in ASP.NET with local host as smtp server in iis7 [Resolved]

Posted by .Netlearner under ASP.NET on 3/20/2013 | Points: 10 | Views : 18540 | Status : [Member] | Replies : 5
Hello all,

I was trying to send emails in my web application.Now i came to know how to send but am using smtp.gmail.com as the smtp server. instead i want to use any other(eg.local host) that sends mail from any network top other network such as outlook to gmail etc




Responses

Posted by: .Netlearner on: 3/22/2013 [Member] Starter | Points: 25

Up
0
Down

Resolved
Hello Aswini,

Thanks for your reply. I Found a solution. What am searching for is to send mail not only from gmail but from any mail domain. so i mentionted

smtp.Host="localhost";

smtp.Port=25;


but i was unable to send mails but no err. This was my issue.

Finally In SMTP properties i changed IP address in general tab to all unassigned and my problem was solved. Now am able to send mail from any email id to any email id.

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 3/21/2013 [Member] Starter | Points: 25

Up
0
Down
hii

you will try this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
//using System.Web.Mail;
using System.Net;
using System.Configuration;
public partial class ASPX_eMails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
try
{
MailMessage msg = new MailMessage(txtfrommailid.Text,txttoemailid.Text,txtsubject.Text.ToString(),txtbody.Text.ToString());
msg.IsBodyHtml = true;
//if (FileUpload1.HasFile)
//{ // msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
//} if (FileUpload1.HasFile)
{ msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
} NetworkCredential Nc = new NetworkCredential(txtfrommailid.Text, "@bangaru");
SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = Nc;
smtp.Send(msg);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Label1.Text = "Your mail is sent sucsessfull";
}}

Thanks & Regards


Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 3/22/2013 [Member] Starter | Points: 25

Up
0
Down
hello .Netlearner
will you please elaborate how you have changed IP address in general tab to all unassigned in smtp properties
thanks

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 3/22/2013 [Member] Starter | Points: 25

Up
0
Down
Right clivk the default SMTP virtual server present in IIS and Choose properties . It wil display property dialog box in which U can see General tab asking for IP address with drop down list having systemIP and all unassigned option.there choose all unassigned.This changed allowed me to send mail specify smtp.Host="localhost" and my mails sent successfully from any emailid such as gmail,yahoo,outlook and myowndomain.

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 3/22/2013 [Member] Starter | Points: 25

Up
0
Down
Right clivk the default SMTP virtual server present in IIS and Choose properties . It wil display property dialog box in which U can see General tab asking for IP address with drop down list having systemIP and all unassigned option.there choose all unassigned.This changed allowed me to send mail specify smtp.Host="localhost" and my mails sent successfully from any emailid such as gmail,yahoo,outlook and myowndomain.

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response