My Personal Blog's
Sending Email by your own Gmail account + Attachment using ASP.NET 2.0 and VB.NET
First of all, you need need to set something in your gmail account to enable sending email using asp.net
1. Open you gmail account and go to setting
2. Click on Forwarding and POP/IMAP
3. Choose Enable POP for mail that arrives from now on
4. Click save changes
Here is the code for sending email from asp.net by using gmail account
create class sendmail.vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Web.Mail
Public Class sendEmail
Public Shared Function SendEmail(ByVal pGmailEmail As String, ByVal pGmailPassword As String, ByVal pTo As String, ByVal pSubject As String, ByVal pBody As String, ByVal pFormat As System.Web.Mail.MailFormat, _
ByVal pAttachmentPath As String) As Boolean
Try
Dim myMail As New System.Web.Mail.MailMessage()
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com")
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465")
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2")
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
'Use 0 for anonymous
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", pGmailEmail)
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pGmailPassword)
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true")
myMail.From = pGmailEmail
myMail.[To] = pTo
myMail.Subject = pSubject
myMail.BodyFormat = pFormat
myMail.Body = pBody
If pAttachmentPath.Trim() <> "" Then
Dim MyAttachment As New MailAttachment(pAttachmentPath)
myMail.Attachments.Add(MyAttachment)
myMail.Priority = System.Web.Mail.MailPriority.High
End If
System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:465"
System.Web.Mail.SmtpMail.Send(myMail)
Return True
Catch ex As Exception
Throw
End Try
End Function
End Class
And this is the code to use the function
SendEmail("youraccount@gmail.com", "yourownGmailPassword", "yourfriend@yahoo.com", "HAHAHAHA", "AAAA", MailFormat.Text, Server.MapPath("Reports/Invoice.pdf"))
No comments yet.
No trackbacks yet.
VB.NET – ASP.NET communication between user control and web page using event handler
April 21, 2011 - 5:09 pm
Posted in ASP.NET | No comments
In this post, we want to show how button in user control communicate with web page in asp.net
First create user control called button.ascx.
Add 3 button, name it btnSave, btnEdit and btnCancel.
in button.ascx back code, add this code:
Public Partial Class button
Inherits System.Web.UI.UserControl
Public Event btnSaveHandler As System.EventHandler
[...]
Get first day of the month and last day of the month in VB.NET
June 3, 2010 - 4:31 pm
Posted in VB.NET | No comments
VB.NET Date Time Format Patterns
January 15, 2010 - 10:00 am
Posted in VB.NET | No comments
Standard Format Example List:
Format
Code
Result
MM/dd/yyyy
Date.Now().ToString(”d”)
1/15/2010
dddd, dd MMMM yyyy
Date.Now().ToString(”D”)
Friday, January 15, 2010
dddd, dd MMMM yyyy hh:mm tt
Date.Now().ToString(”f”)
Friday, January 15, 2010 11:06 AM
dddd, dd MMMM yyyy HH:mm:ss
Date.Now().ToString(”F”)
Friday, January 15, 2010 11:06:46 AM
MM/dd/yyyy h:mm tt
Date.Now().ToString(”g”)
1/15/2010 11:06 AM
MM/dd/yyyy HH:mm:ss
Date.Now().ToString(”G”)
1/15/2010 11:06:46 AM
MMMM dd
Date.Now().ToString(”m”)
January 15
dd MMM yyyy HH’:’mm’:’ss ‘GMT’
Date.Now().ToString(”r”)
Fri, 15 Jan 2010 11:06:46 GMT
yyyy’-’MM’-’dd’T’HH’:’mm’:’ss
Date.Now().ToString(”s”)
2010-01-15T11:06:46
yyyy’-’MM’-’dd HH’:’mm’:’ss’Z’
Date.Now().ToString(”u”)
2010-01-15 11:06:46Z
dddd, MMMM dd yyyy HH:mm:ss
Date.Now().ToString(”U”)
Friday, January [...]
VB.NET: How to implement Group By in DataSet using LINQ
December 10, 2009 - 11:45 am
Posted in LINQ, VB.NET | No comments
ASP.NET: How to read XML Data String to Dataset
December 2, 2009 - 1:54 pm
Posted in VB.NET | No comments
The output of XML String:
<?xml version="1.0" encoding="utf-8" ?>
- <NewDataSet>
- <Table>
<CONDOM>Durex</CONDOM>
<SIZE>XL</SIZE>
<QTY>123</QTY>
<COLOR>616</COLOR>
</Table>
</NewDataSet>
In order to convert from XML to dataset, this is the code:
Dim MyDS as new Dataset("Table1")
Dim strReader As StringReader = New StringReader(YourXmlString)
MyDS.ReadXml(strReader)
ad#300×250]
ASP.NET: How to use Javascript alert inside AJAX UpdatePanel
Normally when we add Javascript Alert to our asp.net it will be like this:
Page. ClientScript.RegisterStartupScript(this.GetType(), "winPop", "alert(’Update is successful’)
but this code is not working if you using the code inside update panel.
So in order to add javascript in update panel you need to register you client script to your script manager as shown below:
ScriptManager.RegisterClientScriptBlock(Page, [...]
Connecting asp.net to Sql server 2005 stored procedures into dataset
June 10, 2009 - 7:20 am
Posted in VB.NET | No comments
This article demonstrates how to use ASP.NET and ADO.NET with Visual Basic .NET to create and to call a Microsoft SQL Server stored procedure with an input parameter and an output parameter.
1 step create store procedure
Create Procedure GetAuthorsByLastName1 (@au_lname varchar(40), @RowCount int output)
as
select * from authors where au_lname like @au_lname;
/* @@ROWCOUNT returns the number of [...]




