5
Reply

Mail box smtp is not working

Kasuni Abegunawardana

Kasuni Abegunawardana

Nov 22 2017 2:33 PM
216
Hi all,
I have created a mail box. It doesn't work. Please can some one tell me why is that?
I created this by watching a video. i don't know i gave his port numbers and all. Is it okay or do i want change it and how can i do that?
It shows me an error message like thsi
**aspx.cs**
public partial class MailBox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//Click event: send button
protected void btn_Send_Click(object sender, EventArgs e)
{
string _from = "[email protected]";
string _to = txt_to.Text.Trim();
string _cc = txt_cc.Text.Trim();
string _bcc = txt_bcc.Text.Trim();
string _subject = txt_sub.Text.Trim();
string _body = txt_body.Text.Trim();
//calling method
SenEmail(_from,_to, _cc, _bcc, _subject, _body,true);
}
private static void SenEmail(string from,string to,string cc, string bcc, string subject,string body,bool IsHTML)
{
//create an instant in mail message
MailMessage tmailmessage = new MailMessage();
//assign sender mail address
tmailmessage.From = new MailAddress(from);
//asssign recipiant email address
tmailmessage.To.Add(new MailAddress(to));
//check if cc/bcc is not null
if (cc != null && cc != "")
tmailmessage.CC.Add(new MailAddress(cc));
if (bcc != null && bcc != "")
tmailmessage.Bcc.Add(new MailAddress(bcc));
//assign the subject
tmailmessage.Subject = subject;
//assign the mail body
tmailmessage.Body = body;
//assign the format into mail box
tmailmessage.IsBodyHtml = IsHTML;
//assign the prority of the mail into normal
tmailmessage.Priority = MailPriority.Normal;
//subject encoding by UTF-8
tmailmessage.SubjectEncoding = System.Text.Encoding.UTF8;
//body encoding by UTF-8
tmailmessage.BodyEncoding = System.Text.Encoding.UTF8;
//Create a new instance of SMTP client and pass name port number from SMPT gmail server
SmtpClient tsmtpClient = new SmtpClient("smpt.gmail.com", 587);
//enable SSL of theamtp client
tsmtpClient.EnableSsl = true;
//use delivery method as network
tsmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
//use the Credentials set to false
tsmtpClient.UseDefaultCredentials = false;
//pass account information to the sender
tsmtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "kasuchin321");
tsmtpClient.Send(tmailmessage);
}}
**Error Message**
Server Error in '/' Application.
The remote name could not be resolved: 'smpt.gmail.com'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote name could not be resolved: 'smpt.gmail.com'
Source Error:
Line 66: //pass account information to the sender
Line 67: tsmtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "kasuchin321");
Line 68: tsmtpClient.Send(tmailmessage);
Line 69:
Line 70:
Source File: c:\Users\A\Desktop\Food new one\Backup\11-21\Food Calorie Calculator- Final Project\Food Calorie Calculator- Final Project\Admin\MailBox.aspx.cs Line: 68
Stack Trace:
[WebException: The remote name could not be resolved: 'smpt.gmail.com']
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) +6646520
System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) +307
System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +19
System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +324
System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +141
System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +170
System.Net.Mail.SmtpClient.GetConnection() +44
System.Net.Mail.SmtpClient.Send(MailMessage message) +1554
[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +1906
Food_Calorie_Calculator__Final_Project.Admin.MailBox.SenEmail(String from, String to, String cc, String bcc, String subject, String body, Boolean IsHTML) in c:\Users\A\Desktop\Food new one\Backup\11-21\Food Calorie Calculator- Final Project\Food Calorie Calculator- Final Project\Admin\MailBox.aspx.cs:68
Food_Calorie_Calculator__Final_Project.Admin.MailBox.btn_Send_Click(Object sender, EventArgs e) in c:\Users\A\Desktop\Food new one\Backup\11-21\Food Calorie Calculator- Final Project\Food Calorie Calculator- Final Project\Admin\MailBox.aspx.cs:29
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628114
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Answers (5)