private void SendGmailMessage()
{
IntPtr bstr = Marshal.SecureStringToBSTR( googlePassword );
string plainGooglePassword = Marshal.PtrToStringAuto( bstr );
Marshal.ZeroFreeBSTR( bstr );
GoogleAccount.Gmail gmailMessage = new GoogleAccount.Gmail( googleUsername, plainGooglePassword );
gmailMessage.OnStatus += new GoogleAccount.Gmail.StatusEventHandler( HandleGmailStatus );
gmailMessage.OnError += new GoogleAccount.Gmail.ErrorEventHandler( HandleGmailError );
foreach ( string recipient in toArray )
{
gmailMessage.To.Add( recipient );
}
foreach ( string recipient in ccArray )
{
gmailMessage.Cc.Add( recipient );
}
foreach ( string recipient in bccArray )
{
gmailMessage.Bcc.Add( recipient );
}
if ( !string.IsNullOrEmpty( subject ) )
{
gmailMessage.Subject = subject;
}
if ( !string.IsNullOrEmpty( body ) )
{
gmailMessage.Body = body;
}
gmailMessage.BodyIsHtml = bodyIsHtml.IsPresent;
gmailMessage.Timeout = timeout;
foreach ( FileInfo attachment in inputAttachments )
{
gmailMessage.Attachments.Add( attachment );
}
if ( ShouldProcess( gmailMessage.Subject ) )
{
gmailMessage.Send();
}
}
You might notice the OnStatus and OnError event handlers being set up at the beginning of the function. These are used to report errors and status messages during the several requests necessary to send an email. These handlers are used by the Send-Email cmdlet to provide proper support for the -Verbose parameter.
protected override void EndProcessing()
{
IntPtr bstr = Marshal.SecureStringToBSTR( googlePassword );
string plainGooglePassword = Marshal.PtrToStringAuto( bstr );
Marshal.ZeroFreeBSTR( bstr );
GoogleAccount.SMS sms = new GoogleAccount.SMS( googleUsername, plainGooglePassword );
sms.OnStatus += new GoogleAccount.SMS.StatusEventHandler( HandleGoogleVoiceStatus );
sms.OnError += new GoogleAccount.SMS.ErrorEventHandler( HandleGoogleVoiceError );
sms.Number = this.number;
sms.Text = this.text;
if ( ShouldProcess( sms.Text ) )
{
sms.Send();
}
}
The Contacts class provides read-only access to each of your Google contacts through a Contact class that has fields for first name, last name, email address, mobile phone, and groups. I create this list by downloading a CSV file and parsing it. Yes, I know I shouldn't parse the CSV data myself, but .NET doesn't have a built-in CSV parser, and I didn't want to add a dependency to a 3rd-party library. It seems to work just fine for its simple purpose.
No comments:
Post a Comment