PDA

View Full Version : حرفه ای: ارسال خودکار ایمیل



araz_pashazadeh
پنج شنبه 31 تیر 1389, 17:36 عصر
با عرض سلام خدمت دوستان
من مدتی دنبال اینم که چطوری می تونم به کابری که آزمون داده به صورت خودکار نتیجه آزمون را ایمیل کنم ولی به نتیجه نرسیدم:متفکر:
آیا دوستان در این ضمینه فعالیت کردن:لبخند:
ممنون می شم اگه بنده را راهنایی کنن:لبخندساده:

ricky22
پنج شنبه 31 تیر 1389, 17:53 عصر
خب وقتی که نتیجه رو ثبت می کنید ایمیل ارسال شه!
من متوجه مشکلتون نشدم
در ارسال ایمیل مشکل دارید؟

araz_pashazadeh
شنبه 02 مرداد 1389, 16:25 عصر
خب وقتی که نتیجه رو ثبت می کنید ایمیل ارسال شه!
من متوجه مشکلتون نشدم
در ارسال ایمیل مشکل دارید؟
دوست من منظور من کاملا واضح بود.
مثلا شما در یک سایتی ثبت نام می کنید بعد از مدتی به ایمیل شما یک پیام خوش آمد گویی ارسال می شود من می خوام این کار به صورت خودکار انجام شود یعنی به محض اینکه کاربر ثبت نام کرد پیامی به ایمیل او فرستاده شود.

ricky22
شنبه 02 مرداد 1389, 16:54 عصر
دوست من منظور من کاملا واضح بود.
مثلا شما در یک سایتی ثبت نام می کنید بعد از مدتی به ایمیل شما یک پیام خوش آمد گویی ارسال می شود من می خوام این کار به صورت خودکار انجام شود یعنی به محض اینکه کاربر ثبت نام کرد پیامی به ایمیل او فرستاده شود.
خب بعد از کد ثبت نام کد ارسال ایمیل رو بزار!
کدی که گزاشتم اون کاری که شما می خواید رو انجام نمیده.
اما مشخص که بعد از یک عملیات ایمیل فرستاده که میشه الگو برداشت

}

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
UserBAL objuserBAL = new UserBAL();
MembershipUser username = Membership.GetUser(CreateUserWizard1.UserName);
try
{


// Membership user = Membership.GetUser(CreateUserWizard1.UserName);
//TblUser user1 = new TblUser();
User user1 = new User();
user1.UserName=CreateUserWizard1.UserName;
user1.MembershipUserId = (Guid)username.ProviderUserKey;


CreateUserWizard1.LoginCreatedUser = false;
username.LastActivityDate = System.DateTime.Today.ToUniversalTime();
Membership.UpdateUser(username);

Roles.AddUserToRole(CreateUserWizard1.UserName,"Others");

TextBox tb1 = (TextBox)CreateUserWizardStep1.ContentTemplateCont ainer.FindControl("txtFirstName");
TextBox tb2 = (TextBox)CreateUserWizardStep1.ContentTemplateCont ainer.FindControl("txtLastName");
user1.FirstName = tb1.Text;
user1.LastName = tb2.Text;


//RadioButtonList rdo = (RadioButtonList)CreateUserWizardStep1.ContentTemp lateContainer.FindControl("RadioButtonList1");
//if ((rdo.SelectedValue != null )&& (rdo.SelectedValue != "" ))
//{
//user1.UserType = Convert.ToInt32(rdo.SelectedValue);
//}
user1.UserType = 1;
user1.SubscriptionId = 0;
int Result = objuserBAL.InsertUser(user1);



MailMessage msgMail = new MailMessage();
//Net Mail
msgMail.From = new MailAddress(Email);
msgMail.To.Add(CreateUserWizard1.Email);
//msgMail.To.Add("mahajan.namrata@yahoo.com");


////Label lblEmail = (Label)GridView1.Rows[i].FindControl("");
//web Mail
//msgMail.To = "nanuramp@synoris.com";
//msgMail.From =("namratam@synoris.com");


Comman objComman = new Comman();
MailTemplate currenttemplate = new MailTemplate();
currenttemplate = objComman.GetTemplate("ActivationEmail");
//currenttemplate.Body = String.Format(currenttemplate.Body,user1.Membershi pUserId.ToString());
//PropertyMapper mapper = new PropertyMapper(user1);
//mapper.MapTemplate(currenttemplate);
//UpdateUI(currenttemplate);
currenttemplate.Body = currenttemplate.Body.Replace("Domain",System.Web.HttpContext.Current.Request.Url.ToStri ng().Replace(System.Web.HttpContext.Current.Reques t.RawUrl.ToString(), ""));
currenttemplate.Body = currenttemplate.Body.Replace("MembershipUserId", user1.MembershipUserId.ToString());
msgMail.Subject = currenttemplate.Subject;
msgMail.Body = currenttemplate.Body;
// msgMail.Subject = "InvestorScopes Account Activation";


// //msgMail.BodyFormat = MailFormat.Html;
// string emailbody = "<b>Thanks for registration in Investor scopes.To Activate your account click on the following link<b>";
// emailbody += "<a href=";

// emailbody += '"';
// // emailbody += "http://www.google.co.in/";


// emailbody += System.Web.HttpContext.Current.Request.Url.ToStrin g().Replace(System.Web.HttpContext.Current.Request .RawUrl.ToString(), "");
// emailbody += "/RegistrationActive.aspx?ID=";


//// emailbody += "http://www.investorscope.synoris.com/RegistrationActive.aspx?ID=";



// emailbody +=(System.Guid)username.ProviderUserKey;
// emailbody += '"';
// emailbody += ">";
// emailbody += "Activate My Account";
// emailbody += "</a>";
// msgMail.Body = emailbody;
//net mail
msgMail.IsBodyHtml = true;
msgMail.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("smtp.gmail.com");
//sC.Port = 25;
sC.Credentials = new NetworkCredential(Email, Pwd);
sC.EnableSsl = true;

//SmtpMail.Send(msgMail);
//net mail
sC.Send(msgMail);
emailid = Encryption.Encrypt(user1.UserName);
// msgMail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
Response.Redirect("ConfirmEmail.aspx?ID=" + username.ProviderUserKey + "&eid=" + emailid);
}
catch(Exception ex)
{




throw new Exception(ex.Message);


Response.Redirect("ConfirmEmail.aspx?ID=" + username.ProviderUserKey + "&eid=" + emailid);
}
finally
{
objuserBAL = null;
}






// }

araz_pashazadeh
دوشنبه 04 مرداد 1389, 13:23 عصر
ممنون از راهنملیی شما ولی من خودم یه چیزهای نوشتم که خطا نداره وقتی در ftp رار می دم تا اجراش کنم باز خطای ندارم ولی نمی دونم چرا ایمیل ارسال نمی کنه:متفکر:
ممنون می شم اگه به کد من نگاهی بکنین.

ricky22
دوشنبه 04 مرداد 1389, 18:48 عصر
چرا FTP ؟
کد خودتون رو بزارید

araz_pashazadeh
سه شنبه 05 مرداد 1389, 10:12 صبح
چرا FTP ؟
کد خودتون رو بزارید
چون دوست من می خوام به کاربر خاصی ایمیل بزنم این کد را من در C# نوشتم و خطای هم نداره ولی نمیدونم چرا ارسال نمی کنه:عصبانی++:
ممنون میشم اگه نگاه بهش بکنین و اگه مشکلی داشت کمکم کنین

ricky22
سه شنبه 05 مرداد 1389, 10:21 صبح
کدتون رو ضمیمه بفرمایید

araz_pashazadeh
سه شنبه 05 مرداد 1389, 10:21 صبح
فایل ضمیمه

ricky22
سه شنبه 05 مرداد 1389, 10:53 صبح
سلام
من کدتون رو نگاه کردم.
روشی که شما استفاده می کنید منسوخ شده و ماکروسافت این روش رو پیشنهاد می کنه :
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
namespace Examples.SmptExamples.Async
{
public class SimpleAsynchronousExample
{
static bool mailSent = false;
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
{
// Get the unique identifier for this asynchronous operation.
String token = (string)e.UserState;

if (e.Cancelled)
{
Console.WriteLine("[{0}] Send canceled.", token);
}
if (e.Error != null)
{
Console.WriteLine("[{0}] {1}", token, e.Error.ToString());
}
else
{
Console.WriteLine("Message sent.");
}
mailSent = true;
}
public static void Main(string[] args)
{
// Command line argument must the the SMTP host.
SmtpClient client = new SmtpClient(args[0]);
// Specify the e-mail sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress("jane@contoso.com",
"Jane " + (char)0xD8 + " Clayton",
System.Text.Encoding.UTF8);
// Set destinations for the e-mail message.
MailAddress to = new MailAddress("ben@contoso.com");
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test e-mail message sent by an application. ";
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// Set the method that is called back when the send operation ends.
client.SendCompleted += new
SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// For this example, the userToken is a string constant.
string userState = "test message1";
client.SendAsync(message, userState);
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
string answer = Console.ReadLine();
// If the user canceled the send, and mail hasn't been sent yet,
// then cancel the pending operation.
if (answer.StartsWith("c") && mailSent == false)
{
client.SendAsyncCancel();
}
// Clean up.
message.Dispose();
Console.WriteLine("Goodbye.");
}
}
}

برای توضحیات بیشتر به این لینک مراجعه کنید.
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
در ضمن ایراد شما smtp یاهو بود که smtp یاهو این نیست(ادرسش رو نمی دونم) و کلا اگه کاربر خواست با Gmail ایمیل بفرسته چه کار می کنید؟
موفق باشید

araz_pashazadeh
چهارشنبه 06 مرداد 1389, 14:40 عصر
خوب یعنی الان این با این کد هم به یاهو و هم به جی میل میشه ارسال کرد؟؟؟

araz_pashazadeh
چهارشنبه 06 مرداد 1389, 16:26 عصر
سلام
من کدتون رو نگاه کردم.
روشی که شما استفاده می کنید منسوخ شده و ماکروسافت این روش رو پیشنهاد می کنه :
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
namespace Examples.SmptExamples.Async
{
public class SimpleAsynchronousExample
{
static bool mailSent = false;
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
{
// Get the unique identifier for this asynchronous operation.
String token = (string)e.UserState;

if (e.Cancelled)
{
Console.WriteLine("[{0}] Send canceled.", token);
}
if (e.Error != null)
{
Console.WriteLine("[{0}] {1}", token, e.Error.ToString());
}
else
{
Console.WriteLine("Message sent.");
}
mailSent = true;
}
public static void Main(string[] args)
{
// Command line argument must the the SMTP host.
SmtpClient client = new SmtpClient(args[0]);
// Specify the e-mail sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress("jane@contoso.com",
"Jane " + (char)0xD8 + " Clayton",
System.Text.Encoding.UTF8);
// Set destinations for the e-mail message.
MailAddress to = new MailAddress("ben@contoso.com");
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test e-mail message sent by an application. ";
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// Set the method that is called back when the send operation ends.
client.SendCompleted += new
SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// For this example, the userToken is a string constant.
string userState = "test message1";
client.SendAsync(message, userState);
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
string answer = Console.ReadLine();
// If the user canceled the send, and mail hasn't been sent yet,
// then cancel the pending operation.
if (answer.StartsWith("c") && mailSent == false)
{
client.SendAsyncCancel();
}
// Clean up.
message.Dispose();
Console.WriteLine("Goodbye.");
}
}
}

برای توضحیات بیشتر به این لینک مراجعه کنید.
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
در ضمن ایراد شما smtp یاهو بود که smtp یاهو این نیست(ادرسش رو نمی دونم) و کلا اگه کاربر خواست با Gmail ایمیل بفرسته چه کار می کنید؟
موفق باشید

دوست عزیز ممنون از راهنمایی شما من به free smtp یاهو نگاه کردم ولی ندونستم از کدام یکی استفاده کنم:متفکر:
در ضمن این کد شما تحت Console تو وب چطوری کار میکونه:لبخند:

ricky22
چهارشنبه 06 مرداد 1389, 19:14 عصر
فرقی نداره شما بدنه همین کد رو ببر تو وب.



خوب یعنی الان این با این کد هم به یاهو و هم به جی میل میشه ارسال کرد؟؟؟
نه برای هر کدام فرق می کنه برای گوگل از این تنظیمات استفاده کن :
http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
اینم یه نمونه دیگه :
http://articles.sitepoint.com/article/sending-web-email-asp-net