aspx email photo submission - asp.net

I am new to asp.net, I am trying to have a photo contest on my website.
I want users to upload their pictures on my site and I want to get an email with the picture attachment to my email ID.
How can I do this and is there a better way of doing this(I have to use asp for this)
Thanks,
jack

It should be relatively simple by using the FileUpload webcontrol on the aspx form and using System.Net.Mail.SmtpClient to send a MailMessage with an attachment.

Well if you wanna do it in vb you would do something like this :
Dim message As New Mail.MailMessage
Using message
message.To.Add(New Mail.MailAddress("notyou#gmail.com", "Name Reciever"))
message.From = New Mail.MailAddress("you#gmail.com", "Name Sender")
message.Subject = "subject!"
message.Body = "Text!"
message.Attachments.Add(New Mail.Attachment("pic.jpg"))
Using smtp As New Net.Mail.SmtpClient("Your smtp")
smtp.Send(message)
End Using
But you prob use c# but you din't say so ... but it prob looks alike anyhow ^^

Related

opening small size window from link send in body of email generated using asp.net

here is my code
System.Text.StringBuilder sb = new System.Text.StringBuilder();
MailMessage message = new MailMessage("abc#gmail.com", txtEmailId.Text.Trim());
message.Subject = "Auto email Test";
message.IsBodyHtml = true;
string str="http://localhost:55243/WebSiteTest/Accept.aspx?id=" + txtEmailId.Text.Trim();
string url = #"<a href="""+str+#""" target='_blank'";
string str1 = "http://localhost:55243/WebSiteTest/Reject.aspx?id=" + txtEmailId.Text.Trim();
string url1 = #"<a href=""" + str1 + #""" target='_blank'";
message.Body = #"<html><body>Thanks For Showing interest in our site. please press "+ url + #">Accept</a>Or "+ url1+">Reject</a></body></html>";
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("abc#gmail.com", "password");
client.Send(message);
it redirects to the aspx page when link is clicked from mail received but as a new tab in browser.
but i need to open the pages in small window that will open on the screen.
any help!!!!!
Thanks in Advance.
You can't do that. You would need javascript to open a window at a certain size, and e-mail cients - reasonably so - do not run javascript in e-mails.
I believe what you're seeing is a combination of markup and browser behavior. In particular, the anchor tags you're generating in the message body both contain the target="_blank" attribute. This tells the browser to open the content in a new window, but doesn't specify the size of the window, so it seems the browser is just opening a new tab in an already opened browser (if no browser is opened a new browser instance altogether is opened).
The behavior you're seeing is not unexpected. As Menno van den Heuvel mentioned, you do need JavaScript to give browsers explicit instructions on the window size. This w3schools.com link has some details on that if you're interested. But, again, as Menno van den Heuvel points out most email clients aren't well equipped to handle JavaScript.

failed sending template within email

in asp.net, i am trying to send a template in an email, so when a user will get a message from my website, then it will be in a template,
e.g. when FB sends you a notification via mail, then it has a header and footer too, so i want to do that, i tried but it isn't sending any template within email body
CODE:
MailDefinition mailDefinition = new MailDefinition();
mailDefinition.BodyFileName = "emailBody.htm";
mailDefinition.From = "hunain.hafeez#gmail.com";
MailMessage message = new MailMessage();
message.From = new MailAddress(user_email);
message.To.Add(new MailAddress(email));
message.Subject = "Registration";
message.IsBodyHtml = true;
message.Body = "Congrats" + " " + userName + " " + " You have been shortlisted for interview. Please appear on " + " " + date +", "+time+" "+ "for interview";
SmtpClient objClient = new SmtpClient("smtp.gmail.com", 587);
objClient.EnableSsl = true;
objClient.Credentials = new System.Net.NetworkCredential("hunain.hafeez", "*******");
Short Answer: For quick fix use HTML mark-up templates , however a more flexible solution is Razor with email templating.
There are different approaches on how to achieve this. However, I stumbled upon a greate article about how to use Razor with email templating. Razor was pushed with ASP.NET MVC 3, but MVC is not required to use Razor. This is pretty slick processing of doing email templates
As the article identifies, "The best thing of Razor is that unlike its predecessor(webforms) it is not tied with the web environment, we can easily host it outside the web and use it as template engine for various purpose. "
Use Razor for Email Template outside ASP.NET MVC
Your message body needs to have HTML markup in it.
ie:
<html><body><b>Congrats ....

E-Mails sent from online form are coming in one single mail

I'm using an online form at one of my web sites. Every mail sent from this form is coming in one mail even if the senders IP is different.
But I want every single mail to be unique even if the content is same. What I need to do to the mails or which header I need to modify?
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("no-reply#toprakbasim.com", "NoReply");
MailAddress toAddress = new MailAddress("info#toprakbasim.com", "Info");
MailAddress toSender = new MailAddress(tEMail.Text, tNameSurname.Text);
message.From = fromAddress;
message.Bcc.Add(toAddress);
message.ReplyTo = toSender;
message.Subject = tNameSurname.Text + " : contact";
message.IsBodyHtml = true;
message.Body = "some html here";
smtpClient.Send(message);
Gmail will group emails with the same subject line together. Put some text in the subject line to make it unique, like MessageID, time, whatever.
If you are saying the content in the body contains more than one response, then the issue is how you are collecting the text that then gets assigned to message.Body. If the text is in a variable before assigning to message.Body, make sure that you are not re-using the variable and that it gets re-instantiated each time.
What are you using for a mail reader program? Because it sounds like that program is rolling your emails up for you. (Outlook 2010 does this, by default).
Try reading your email with a different email reader (like Outlook Express, or tbird)

Use ASP.NET to e-mail contents of an entire HTML Page?

I have a HTML page that I have created that essentially consists of:
<div>
<table>
<tr>
<td><asp:label runat="server" id="someText"></asp:label></td>
</tr>
</table>
</div>
The label text is generated on page load from an SQL query.
The above is a very basic and simplified version of what I have on my page.
What I'd like to achieve is to be able to e-mail the entirety of the rendered HTML page without having to build the page again in my code-behind to send it.
Is there a way of doing this?
Thanks in advance for any help.
Something like this maybe (haven't tested):
StringBuilder sb = new StringBuilder();
HtmlTextWriter hw = new HtmlTextWriter(new System.IO.StringWriter(sb));
this.Render(hw);
MailMessage message = new MailMessage();
message.IsBodyHtml = true;
message.Body = sb.ToString();
(new SmtpClient()).Send(message);
If you want to send the email as you render the page, without rerunning the page lifecycle, try the following.
Make a wrapper stream class that inherits Stream and contains two additional streams, and override its Write method to write to both streams. I don't think you need to override anything else except the Can_Whaterver_ properties, but I'm not sure.
Make a field in your Page class of type MemoryStream to hold a copy of the response.
Then, handle the page's PreInit event and set the Response.Filter, like this:
Response.Filter = new CopierStream(Response.Filter, responseCopy);
//`CopierStream` is the custom stream class; `responseCopy` is the MemoryStream
Finally, override the Page's Render method, and, after calling base.Render, you can send responseCopy by email using the SmtpClient class.
This is a very complicated technique that you should only do if you really don't want to re-run the page lifecycle.
Whichever way you do it, if your page has any images or hyperlinks, make sure that their urls include the domain name, or else they won't work in the email.
Use a webclient:
Dim wc As New WebClient
Dim str As String = wc.DownloadString("yoururl.com")
SendEmail(str) ' your email method '

How the send a webform by email

I have a task in hand that requires me to send a form to a client by email as soon as it is submited.
My question is: Having an aspx(in order to reuse my form) how can I get the generated html to send it by mail?
Thanks in advance
EDIT:
I know how to send emails, what I am looking for is how to get the html that is generated in my webform so i can place it in the email.
You should be able to call Render on it and stream it.
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
Page.RenderControl(htmlWriter);
string output = stringWriter.ToString();
Using the SmtpMail class in System.Web?

Resources