PDA

View Full Version : مشکل ارسال ایمیل



korosh00
چهارشنبه 23 مرداد 1392, 15:48 عصر
سلام
من با این کد ها ایمیل می زنم
ایمیل از جی میل به ایمیل میره ولی متن ارسال نمیشه
ی اخطار از جی میل میرسته به ایمیلی که کاربر وارد میکنه میگه یکی میخواد جی میل را هک کنه




protected void SendMail()

{



// Gmail Address from where you send the mail



var fromAddress = "اااا@gmail.com";



// any address where the email will be sending



var toAddress = YourEmail.Text.ToString();



//Password of your gmail address



const string fromPassword = "************";



// Passing the values and make a email formate to display



string subject = YourSubject.Text.ToString();



string body = "From: " + YourName.Text + "\n";

body +=

"Email: " + YourEmail.Text + "\n";

body +=

"Subject: " + YourSubject.Text + "\n";

body +=

"Question: \n" + Comments.Text + "\n";



// smtp settings



var smtp = new System.Net.Mail.SmtpClient();

{

smtp.Host =

"smtp.gmail.com";

smtp.Port = 587;

smtp.EnableSsl =

true;

smtp.DeliveryMethod = System.Net.Mail.

SmtpDeliveryMethod.Network;

smtp.Credentials =

new NetworkCredential(fromAddress, fromPassword);

smtp.Timeout = 20000;

}



// Passing values to smtp object

smtp.Send(fromAddress, toAddress, subject, body);

}

 

 



protected void Button1_Click(object sender, EventArgs e)

{



try

{



//here on button click what will done

SendMail();

DisplayMessage.Text =

"Your Comments after sending the mail";

DisplayMessage.Visible =

true;

YourSubject.Text =

"";

YourEmail.Text =

"";

YourName.Text =

"";

Comments.Text =

"";

}



catch (Exception) { }

 

}

korosh00
چهارشنبه 23 مرداد 1392, 21:11 عصر
کیست مرا یاری کند ؟

uthman
چهارشنبه 23 مرداد 1392, 21:41 عصر
سلام.


protected void Button1_Click(object sender, EventArgs e)
{
string smtpServer = "";
int smtpPort = 0;
bool sslSupport = false;

MailMessage message = new MailMessage();

try
{

MailAddress fromAddress = new MailAddress("Emaili ke mi khahid ba an ersal konid");
message.From = fromAddress;
message.To.Add("Email Girande");
message.Subject = "Subject";
message.IsBodyHtml = true;
message.Body ="";

smtpServer = "smtp.mail.yahoo.com";
smtpPort = 587;

SmtpClient smtpClient = new SmtpClient(smtpServer, smtpPort);
smtpClient.EnableSsl = sslSupport;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("Emaili ke mi khahid ba an ersal konid","Password Emaili ke mi khahid ba an ersal konid");

smtpClient.Send(message);
Response.Write("<script language=\"javascript\">alert(\"Thank you. Sent\")</script>");


}
catch (Exception ex)
{

Response.Write("<script language=\"javascript\">alert(\"Not sent. Please try again\")</script>");

}




و در انتها :
1-فضای نام

using System.Net.Mail;

رو add کن
2-در صفحه .aspx در خط اول کد زیر رو add کن.

ValidateRequest="false"