الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Sending Mails With Asp.net

بدأه mohamed_en في 25 مارس 2008 · 4 رد · 1,579 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

I have a problem with sending mails with ASP.NET when I am trying to use the System.Net.Mail

the code is below :

public void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body) {

// Instantiate a new instance of MailMessage

MailMessage mMailMessage = new MailMessage();</FONT> // Set the sender address of the mail message

mMailMessage.From = new MailAddress(from);</FONT> // Set the recepient address of the mail message

mMailMessage.To.Add(new MailAddress(to));</FONT> // Check if the bcc value is null or an empty string

if ((bcc != null) && (bcc != string.Empty))</FONT> {

// Set the Bcc address of the mail message

mMailMessage.Bcc.Add(new MailAddress(bcc));</FONT> }

// Check if the cc value is null or an empty value

if ((cc != null) && (cc != string.Empty))</FONT> {

// Set the CC address of the mail message

mMailMessage.CC.Add(new MailAddress(cc));</FONT> } // Set the subject of the mail message

mMailMessage.Subject = subject;

// Set the body of the mail message

mMailMessage.Body = body;

// Set the format of the mail message body as HTML

mMailMessage.IsBodyHtml = true;</FONT> // Set the priority of the mail message to normal

mMailMessage.Priority = MailPriority.Normal;</FONT> // Instantiate a new instance of SmtpClient

SmtpClient mSmtpClient = new SmtpClient();</FONT> // Send the mail message

mSmtpClient.Send(mMailMessage);

}

SendMailMessage("mohamed_alaa_younis@hotmail.com", "mohamed_alaa_younis@yahoo.com", "", "", "i love you", "hello mohamed i want to be your friend !");

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Then the error appears when running the website :

No connection could be made because the target machine actively refused it 127.0.0.1:50025

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.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25

What should I do ?

#2

السلام عليكم ورحمة الله

أخي الكريم يجب عليك تحديد سيرفر البريد الذي تريد الارسال منه

مثلا

mSmtpClient.host="mail.yourdomain.com";

او استخدم Gmail مثلا

mSmtpClient.host="pop.gmail.com";

mSmtpClient.port=995;

لان ارسال البريد بحاجة الى سيرفر

ثم استخدم البحث فهناك العديد من المشاركات بهذا الخصوص

#3
TareqVB كتب:
السلام عليكم ورحمة الله

أخي الكريم يجب عليك تحديد سيرفر البريد الذي تريد الارسال منه

مثلا

mSmtpClient.host="mail.yourdomain.com";

او استخدم Gmail مثلا

mSmtpClient.host="pop.gmail.com";

mSmtpClient.port=995;

لان ارسال البريد بحاجة الى سيرفر

ثم استخدم البحث فهناك العديد من المشاركات بهذا الخصوص

لقد فعلت مثلما قلت بالظبط ولكن هناك شيئا غريبا لا اعلم ما السبب وظهر هذا الخطأ بعد طول انتظار

The operation has timed out.

ومشكور على مرورك اخى

#4

لدي عدة استفسارات في نفس المجال

1- بالنسبه لارسال إيميل فأنا أحتاج لـــ SMTP Server لذا قمت بتحميل الــIIS لكنني واجهت مشاكل في اضافتها للوندوز ولا أعلم كيف يمكنني ربطها بالــASP

2- كيف احدد السيرفر الذي سأرسل منه ,

هل بإمكاني استخدام طريقه تسمح بالارسال إلى مختلف الايميلات (hotmail , yahoo , gmail..............)

#5

السلام عليكم ورحمة الله

اخواني الكرام هذا الموضوع موجود بكثرة في هذا المنتدى بقليل من البحث تجد ما تريد .

لارسال بريد افتح web.config وضع مايلي

<system.net>
	<mailSettings>
	  <smtp>
		<network 
			 host="pop.gmail.com" 
			 port="995"
			 userName="username"
			 password="password" />
	  </smtp>
	</mailSettings>
  </system.net>

وانتبه ان لا تكون موجودة من قبل وان كانت system.net فضعها بينها.

كذلك بحاجة الى بريد Gmail وتفعيل pop به (http://gmail.google.com/support/bin/answer.py?answer=13273)

للارسال

Dim mm As New MailMessage("MyEmail", "ToAddress")


	mm.Subject = "Subject.Text"
	mm.Body =" Body.Text"
	mm.IsBodyHtml = False


	Dim smtp As New SmtpClient


	smtp.Send(mm)

مع تغيير القيم بما يناسب

مواضيع مشابهة