Need to show MODALPOPUP Extender while clickig on Link button - c#

Need to show MODALPOPUP Extender while clickig on Link button and in modal pop up extender we need to get send an email to the required mail ID holder.
Is there any specifications and functionality to use in ASP.NET with C#.Please suggest me the best.
Thanks in advance

First of all add below mentioned namespace in code behind of aspx page from which you want to send the mail.
using System.Net.Mail;
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To.Add("Email ID where email is to be send");
mail.To.Add("Another Email ID where you wanna send same email");
mail.From = new MailAddress("YourGmailID#gmail.com");
mail.Subject = "Email using Gmail";
string Body = "Hi, this mail is to test sending mail"+
"using Gmail in ASP.NET";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential
("YourUserName#gmail.com","YourGmailPassword");
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);
}
For sending mail try the above code in C#
opening the Modalpopup extender on button click
<div id="hiddenDiv" style="display:none; visibility:hidden;">
<asp:Button runat="server" ID="hiddenButton" />
/div>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderID" runat="server"
BehaviorID="ModalPopupBehaviorID"
TargetControlID="hiddenButton"
PopupControlID="ModalContainer"
/>
...
//Javascript
var modalPopupBehaviorCtrl = $find('ModalPopupBehaviorID');
modalPopupBehaviorCtrl.show();

Related

send an email using SMTP without password in C#

I have a web application using ASP.net and C#,in one step it will need
from the user to
send an email to someone with an attachments.
my problem is when the user will send the email i don't want to put their
password every time the user send.
i want to send an email without the password of the sender.
any way to do that using SMTP ?
and this is a sample of my code "not all".
the code is worked correctly when i put my password , but without it ,it
is not work, i need a way to send emails without put the password but
in the same time using smtp protocol.
private void button1_Click(object sender, EventArgs e)
{
string smtpAddress = "smtp.office365.com";
int portNumber = 587;
bool enableSSL = true;
string emailFrom = "my email";
string password = "******";
string emailTo = "receiver mail";
string subject = "Hello";
string body = "Hello, I'm just writing this to say Hi!";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
// Can set to false, if you are sending pure text.
// mail.Attachments.Add(new Attachment("C:\\SomeFile.txt"));
// mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));
using (SmtpClient smtp = new SmtpClient(smtpAddress,portNumber))
{
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
}
MessageBox.Show("message sent");
}
}
I believe this can be accomplished easily, but with some restrictions.
Have a look at the MSDN article on configuring SMTP in your config file.
If your SMTP server allows it, your email object's from address may not need to be the same as the credentials used to connect to the SMTP server.
So, set the from address of your email object as you already are:
mail.From = new MailAddress(emailFrom);
But, configure your smtp connection one of two ways:
Set your app to run under an account that has permission to access the SMTP server
Include credentials for the SMTP server in your config, like this.
Then, just do something like this:
using (SmtpClient smtp = new SmtpClient())
{
smtp.Send(mail);
}
Let the configuration file handle setting up SMTP for you. This is also great because you don't need to change any of your code if you switch servers.
Just remember to be careful with any sensitive settings in your config file! (AKA, don't check them into a public github repo)

How to click button and open window to send email in c#

I want to create a button so that user can click and it will open a small new window where they can send email. This window will have "From", "To", "Subject", "Content" fields and all of that will have default text, user can edit them (except for "From" field). See image below:
What I tried:
I created an email form by:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<p>
From:<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</p>
To:<asp:Literal ID="Literal2" runat="server"></asp:Literal>
<p>
Subject:<asp:Literal ID="Literal3" runat="server"></asp:Literal>
</p>
Content:<asp:Literal ID="Literal4" runat="server"></asp:Literal>
</form>
</body>
</html>
Then I try to link this form with my current code:
Current code: I can send email by this code:
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtpclientaddresshere");
mail.From = new MailAddress("defaultFromEmail#domain.com");
mail.To.Add("email1#yahoo.com,email2#yahoo.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail";
SmtpServer.Credentials = new System.Net.NetworkCredential("mysmtpserver#something.com", "");
SmtpServer.Send(mail);
Now I don't know is this right to use the form above for email window purpose? And how could I format and link all the fields to my working code?
What I have done is like this:
public void SendEmail(string _from, string _fromDisplayName, string _to, string _toDisplayName, string _subject, string _body, string _password)
{
try
{
SmtpClient _smtp = new SmtpClient();
MailMessage _message = new MailMessage();
_message.From = new MailAddress(_from, _fromDisplayName); // Your email address and your full name
_message.To.Add(new MailAddress(_to, _toDisplayName)); // The recipient email address and the recipient full name // Cannot be edited
_message.Subject = _subject; // The subject of the email
_message.Body = _body; // The body of the email
_smtp.Port = 587; // Google mail port
_smtp.Host = "smtp.gmail.com"; // Google mail address
_smtp.EnableSsl = true;
_smtp.UseDefaultCredentials = false;
_smtp.Credentials = new NetworkCredential(_from, _password); // Login the gmail using your email address and password
_smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
_smtp.Send(_message);
ShowMessageBox("Your message has been successfully sent.", "Success", 2);
}
catch (Exception ex)
{
ShowMessageBox("Message : " + ex.Message + "\n\nEither your e-mail or password incorrect. (Are you using Gmail account?)", "Error", 1);
}
}
And I am using it like this:
SendEmail(textBox2.Text, textBox5.Text, textBox3.Text, "YOUR_FULL_NAME", textBox4.Text, textBox6.Text, "YOUR_EMAIL_PASSWORD");
Here is the image:
(Although I am using WinForms and not Windows Presentation Forms).
May this answer would help you.
Cheers!

how to send shopping item on email of user

I want to send shopping cart item list that user purchased from website to registered user. How to send product list that user purchased with user's information in mvc?
I used for loop in mvc controller to display purchase order list and tried to save it in email body but it gives me error. Please suggest me how to save whole data into email body.
Following is the code snippet I have used for mailing purpose.
MailMessage mail = new MailMessage();
mail.To.Add("receiver");
mail.From = new MailAddress("onlinebartan#onlinebartan.com");
mail.Subject = "OnlineBartan:Thanks For Order";
string Body = "s" + orderproduct[1].OrderId +"sdfs";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtpout.asia.secureserver.net";
smtp.Port = 25;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential
("onlinebartan#onlinebartan.com", "Mukesh#1980");
smtp.EnableSsl = false;
smtp.Send(mail);
You can loop through list and append in string
string Body="";
for(int i=0;i<orderproduct.Count;i++)
Body += "s" + orderproduct[i].OrderId +"sdfs <br />";
You have not specified exact error you are getting but I can immediately see is you should set valid html string to mail.Body property when you're setting mail.IsBodyHtml = true.
Hope this helps.

Email id address issue in c# code

I wrote a simple program in C# Winforms for sending an email and my code is mentioned below:-
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public MailMessage rtnMail()
{
string to = txt_To.Text;
string from = txt_From.Text;
string subject = txt_Subject.Text;
string body = txt_Body.Text;
MailMessage message = new MailMessage(from, to, subject, body);
return message;
}
//Button click event
private void btn_Send_Click(object sender, EventArgs e)
{
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("myanotherid#gmail.com", "password");
smtp.EnableSsl = true;
smtp.Timeout = 500000;
smtp.Send(this.rtnMail());
}
}
when i run this code and put all the values in textboxes like (to, from, body, subject) and click the "Send" button i do end up getting an email at an address
mentioned in the Textbox named txt_To ( which is my recipient gmail account id).But whenever i look at which address(email id) i got this email from in Microsoft
Outlook (which i have configued for my gmail recipeint account), it always says that i got this email from the email address mentioned as first argument in the line of
code below,
smtp.Credentials = new System.Net.NetworkCredential("myanotherid#gmail.com", "password");
My question is, am i doing anything wrong because i expect that email address from which im receiving an email( in my outlook gmail) should be the one that i put in
TextBox named txt_From rather than from "myanotherid#gmail.com" address.
Is there a work around or does there exist an alternate to it.
I guess it's gmail's protection to prevent sender spoofing.
You can't login to GMail as yogibear#gmail.com and send an e-mail as barack.obama#whitehouse.gov. GMail's SMTP will rewrite the message's header to properly indicate who has really sent the e-mail.
You should use new mailaddress();
MailAddress from = new MailAddress("someone#something.com", "John Doe");
MailAddress to = new MailAddress("someoneelse#something.com", "Jane Doe");
MailMessage mail = new MailMessage(from, to);
further reading here: http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx
Your code looks correct. Gmail does not allow you to specify a different 'from address' unless it is one you have proven belongs to you.
Go to Settings > Accounts > 'Send email as' and add an address there. You can only choose to send from any of the accounts you have configured here.

how to make disable or unvisible email link when the it is clicked, also, how can i use general smtp server?

I tried some codes but after it is send to mail account, it is always the active how can it become passive link .
string UName = GetNewValidationCode();
// Now lets create an email message
SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
var mail = new MailMessage();
mail.From = new MailAddress("bilkentliaslan#windowslive.com");
mail.To.Add(TextBox6.Text);
mail.Subject = "Registration";
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = string.Format("Thank you for creating an account with YourDomain.com</ br>"+"Please click the below link to activate your account <br />"+"<a href='http://localhost:2386/ActivateUser.aspx?userName{0}&Id={1}'>Activate {0} </a>", UName, user_name);
mail.Body = htmlBody;
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("bilkentliaslan#windowslive.com", "my password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
// Redirecto to What ever page
Response.Redirect("Login.aspx");
Keep a table that stores the waiting IDs, i.e., the IDs that you have sent an email about, but which are not yet activated.
Then in the code of your ActivateUser.aspx (actually in the back-end code that that page then calls), check if the row exists, perform the user activation work and then remove the row from the table. If the user then goes to the very same URL again later, the row won't be there and the user won't be (re-)activated.

Categories

Resources