All rights are reserved by Niteesh Kumar.. Theme images by Storman. Powered by Blogger.

Followers

Total Pageviews

Blog archive

Follow by Email

Translate

Featured Posts

Thursday, 19 November 2020

React-Native static images not loading in iOS - Xcode 12

- No comments


Static images are not loading in React-Native iOS Application when working with React-Native version 0.60 and above and Xcode 12. This is because of some changes in Image component of React-Native latest version.


To resolve the issue of React-Native image not loading please follow the below steps - 

  • Copy and paste below code to the end of your Podfile - 

pre_install do |installer|
puts("Image fix for ios14: remove this when upgradeing to >= 0.63.3")
find = "_currentFrame.CGImage;"
replace = "_currentFrame.CGImage ;} else { [super displayLayer:layer];"
op = `sed -ie "s/#{find}/#{replace}/"
    ../node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m`
puts("Image fix for ios14 done")
end


  • Go to the project directory and run below commands -

     cd ios && pod install

  • Run your application and you will see it's working. 



Monday, 9 November 2020

Undefined is not an object (evaluating 'Component.propsType') - React-Native 0.61.5

- No comments


 While working with React-Native Android Application sometimes we face this issue saying - 

Undefined is not an object (evaluating 'Component.propsType').


This issue generally occurs when our npm package versions get altered somehow. 


I have faced this error while trying to optimize my package.json. I have tried a lot of option cleaning Build folder, Resetting cache etc. but nothing worked.



Here are the few steps to resolve the error Undefined is not an object (evaluating 'Component.propsType').


  1. Make Sure you Reverse all your changes made in your package.json file.
  2. Delete node_modules folder inside your react-native application code
  3. Delete package-lock.json file
  4. Go To Android Studio/Build/Clean and clean the project build
  5. After that do npm install in your react-native project directory
  6. Run npm start --reset-cache to reset bundler cache
  7. After that run react-native run-android 
  8. It will start working now



Wednesday, 4 November 2020

Turbo C uses and drawbacks

- No comments

 Turbo C is basically a software tool that is used to compile and run C language programs.

Turbo C Uses - 

  1. As an editor for C language coding
  2. To compile and run C programs
  3. Can be used to write Assembly language code inside C program without any separate compilers
  4. Can optimize size of a executable program or fast execution for the same





Turbo C Drawbacks - 

  1. Executable program produce by Turbo C does not run on operating system other than MS-DOS.
  2. It only compiles C programs
  3. Turbo C can not be used to develop real world Applications
  4. Turbo C does not support dynamic loadable modules
  5. Turbo C does not have a good debugger
  6. Memory limitation - Program can only use 64kb of memory that is not sufficient.
  7. No Straightforward way for Network programming.

Although there can be more used or drawback of Turbo C. I have mentioned few of them here.




Monday, 2 November 2020

How to check whether port number is already in use or not?

- No comments


How to check whether port number is in use or not?

Sometimes we get the "PORT xxxx is already in use" error when trying to run an application. We also face this issue sometimes when while trying to access the any particular PORT number.

To check whether any particular port number is in use or not follow the  steps given below - 

  • Open "Terminal"
  • Type Below Command in Terminal window -     


     netstat -vanp tcp | grep 3000 // Replace 3000 with PORT Number


  • Replace 3000 with your PORT Number 
  • Click "Enter" and you will see the results in the screen.

Now if you want to make this port idle or available to use you just need to find the "PID" that will be there in the result of above command. 

After finding the "PID" of the process using this port number run the below command - 

kill "pid_value"


After running this command if you will run the command to search the port number you will see empty result.


Sunday, 1 November 2020

Multithreading C++ code

- No comments


Multithreading in C++ - 

 
In Operating system, Multithreading provides the capability to process multiple threads at the same time by a CPU rather than processing multiple processes. 

Examples of Multithreading - 

  • Spelling checker and Grammar checker in Microsoft word at the same time

Below is c++ implementation of multithreading.

Here we are multiplying two matrices using multithreading - 

C++ code for Multithreading -


#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<semaphore.h>
#include<sys/types.h>
#include<pthread.h>
#define pf printf
#define sf scanf
int m1[100][100],m2[100][100],i,j,k,res[100][100],r,c,sum;
void *input(void *arg)
{
pf("enter the size of matrix m1(row*col):\n");
sf("%d%d",&r,&c);
printf("enter the matrix elements:\n");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
sf("%d",&m1[i][j]);
pf("enter the size of matrix m2(row*col):\n");
sf("%d%d",&r,&c);
printf("enter the matrix elements:\n");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
sf("%d",&m2[i][j]);
}
void *multiplication(void *arg)
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
sum=0;
for(k=0;k<r;k++)
sum+=m1[i][k]*m2[k][j];
res[i][j]=sum;
}
}
}
void *print(void *arg)
{
pf("Resultant Matrix:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
pf("%d ",res[i][j]);
pf("\n");
}
}
int main()
{
pthread_t p[3];
pthread_create(&p[0],NULL,input,NULL);
sleep(15);
pthread_create(&p[1],NULL,multiplication,NULL);
pthread_create(&p[2],NULL,print,NULL);
pthread_join(p[0],NULL);
pthread_join(p[1],NULL);
pthread_join(p[2],NULL);
return 0;
}


Wednesday, 28 October 2020

How to clone single branch from a repository git?

- No comments

git clone -b <<---Branch Name-->> --single-branch <<----origin Endpoint----->>>


GitHub is most popular when it comes to collaborative work on code. It is widely used by corporate organizations as well as individual developers.


How to clone single branch from a repository git?
Source - Medium.com


How to clone single branch?

Suppose there are multiple branches of a repository and you want to clone only single branch out of that repository.

You can use the below command for the same - 


git clone -b <<---Branch Name-->> --single-branch <<----origin Endpoint----->>>





Saturday, 18 April 2020

OAM authentication not wroking in react native iOS (Unable to open URL in iOS)

- No comments
If you  using "react-native-webview": "^9.1.0" in your application and trying to implement OAM authentication in your react native application it will show error saying Unable to open URL in iOS. 

The problem is with react-native-webview version. I was facing the same problem and resolved the unable to open URL issue in iOS by downgrading the react-native-webview version to 8.0.6.

"react-native-webview": "8.0.6",


Monday, 13 January 2020

spawnsync ./gradlew eacces react native

- No comments
This is a permission issue mostly occurs while running on macOS.

You can resole this error -  spawnsync ./gradlew eacces react native by giving permission to the gradlew directory-

Go to the project directory and run below command-


chmod 755 android/gradlew

Tuesday, 13 August 2019

React Native Orientation not working iOS

- 7 comments


While developing React Native Mobile Applications we often face challenges regarding device orientation. Common issues that we face are - 

  1. Get device Orientation
  2. Lock application to portrait mode 
  3. Lock application to landscape 
  4. Lock application to portrait mode and enable landscape mode for some screens only

for all those requirements listed above, we use the react-native-orientation library.

To setup the library follow the steps given in the documentation of react-native-orientation. follow the URL given below-


While setting up the library keep this thing in mind that in case of iOS linking the documentation says that you have to add following lines in AppDeligate.m file - 

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]) {< [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; } return [Orientation getOrientation];
}


What I have noticed is that after making this change we will see some issues in iOS. Such that - 
  1. OrientaionListener is not working after lockToPortrait() or lockToLandscape() or UnlockAllOrientation()
  2. lockToPortrait() or lockToLandscape() or UnlockAllOrientation() are not working
  3. The device is not coming back to portrait mode after switching to landscape mode
  4. The device is not coming back to landscape mode after switching to portrait mode
To fix all those issues we need to make the below change. Instead of adding the lines sown above you only have to add the lines below-






- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return [Orientation getOrientation];
}

Because while loop in this creating problem and because of this some times orientation listeners are not getting triggered. 




Wednesday, 8 May 2019

React Native Push Notification Android & iOS

- 2 comments

Today We are going to discuss How to set up React Native Push Notification with react native for both Android and iOS. There are multiple packages available to implement the same. for example-


  1. react-native-firebase
  2. react-native-push-notification
  3. react-native-fcm
I have tried all three packages mentioned above. But today I am going to discuss react-native-push-notification as after trying all three of them I found this on more convenient to use.

First We will discuss how to setup react-native-push-notification for Android & iOS in your react native project.

react-native-push-notification


Step by Step Guide to Set Up React Native Push Notification-  

1 - First of all, install react native push notification package in your react native project. Use the command given below -

npm install --save react-native-push-notification For iOS you can also use - yarn add react-native-push-notification

2 - If you will go through react native push notification official documentation you will see react-native link react-native-push-notification. But this will not link the package completely and you may face some problem. So it's we should link manually.


React Native Push Notification Android Manual Linking -

1 - Go at android/app/build.gradle and add the following dependencies - 

dependencies { ...... implementation project(':react-native-push-notification') implementation ('com.google.android.gms:play-services-gcm:8.1.0') ...... }

You can use a specific gcm-play-service version and change the version number 8.1.0 for your version. In some cases, you may see an error like gcm-play-service version is 16.1.0 at run time but it is getting 8.1.0 at compile time.
So, in that case, change the version number from 8.1.0 to 16.1.0.

2 -  Now go to your android/app/src/AndroidMenifest.xml file and add the following changes - 

Just below uses-permission add the following lines -


<uses-permission android:name="android.permission.WAKE_LOCK" /> <permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

and just before closing application tag add the lines given below-


<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name" android:value="YOUR NOTIFICATION CHANNEL NAME"/> <meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description" android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/> <meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@android:color/white"/> <receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" /> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/> <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm" android:exported="false" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service> <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="false" > <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>

NOTE -  Replace ${applicationId} with the application ID that you are using in firebase application. As your application id should be same both in the firebase application that you have created for the push notification and the project you are working in. 

Go to your android/app/build.gradle file and you will find applicationId in defaultconfig

3 - Now go to your MainActivity.java file inside android/src/main/java... and do the following steps - 

Add the line below in the imports of your MainActivity.java  -


import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;

Add the following line inside the implementation of MainApplication - 


@Override protected List<ReactPackage> getPackages() { return Arrays.<reactpackage>asList( new MainReactPackage(), new ReactNativePushNotificationPackage(), //Add This Line

4 -  Go to your settings.gradle file and add the following line on the bottom of the file - 

include ':react-native-push-notification' project(':react-native-push-notification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-push-notification/android')

Now you are done with linking react-native-push-notification package for Android.




React Native Push Notification iOS Manual Linking -

For iOS, we will be using PushNotificationIOS library that is provided by react-native itself. To use this you need to link the PushNotificationIOS library from X-Code to your project. Follow the URL given below to manually link this library with your react native project-


After Successfully linking this library follow the steps given below for further set up of iOS push notification set up -
1 - To enable the support for push notification and register event you need to make some changes in your AppDeligate.

Add the below line on the top of your Appdelegate.m file -  

#import <React/RCTPushNotificationManager.h>
  
2 - After this add the blow lines in your AppDelegate Implementation just above @end


// Required to register for notifications - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings]; } // Required for the register event. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion //handler after handling the remote notification. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for the localNotification event. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [RCTPushNotificationManager didReceiveLocalNotification:notification]; }

Now for iOS we are done setting up react native push notification.


Wednesday, 1 May 2019

Composite Transformation

- No comments

What is Composite Transformation?

When we are performing two or more transformations in a geometric figure to create a new figure or shape, we call it a composite transformation.

In the code given below, you will get a choice that which transformation you want to perform in the given figure among Translation, Rotation, and Scaling.





#include bits/stdc++.h ;
#include graphics.h; using namespace std; int gd,gm; //function for rotation void rotation(int side[][3],int n) { int theta,res[100][100]; printf("Enter the rotation angle:"); scanf("%d",&theta); int mat[3][3]={{cos(theta),sin(theta),0},{-sin(theta),cos(theta),0},{0,0,1}}; detectgraph(&gd,&gm); initgraph(&gd,&gm,""); for(int i=0;i<n-1;i++) line(side[i][0],side[i][1],side[i+1][0],side[i+1][1]);\ line(side[n-1][0],side[n-1][1],side[0][0],side[0][1]); for(int i=0;i<n;i++) for(int j=0;j<3;j++) for(int k=0;k<3;k++) res[i][j]+=side[i][k]*mat[k][j]; for(int i=0;i<n-1;i++) line(res[i][0],res[i][1],res[i+1][0],res[i+1][1]); line(res[n-1][0],res[n-1][1],res[0][0],res[0][1]); getch(); } //function for scaling void scaling(int side[][3],int n) { int sx,sy,res[100][100]; printf("Enter the scaling co-ordinates:"); scanf("%d%d",&sx,&sy); int mat[3][3]={{sx,0,0},{0,sy,0},{0,0,1}}; detectgraph(&gd,&gm); initgraph(&gd,&gm,""); for(int i=0;i<n-1;i++) line(side[i][0],side[i][1],side[i+1][0],side[i+1][1]); line(side[n-1][0],side[n-1][1],side[0][0],side[0][1]); for(int i=0;i<n;i++) for(int j=0;j<3;j++) for(int k=0;k<3;k++) res[i][j]+=side[i][k]*mat[k][j]; for(int i=0;i<n-1;i++) line(res[i][0],res[i][1],res[i+1][0],res[i+1][1]); line(res[n-1][0],res[n-1][1],res[0][0],res[0][1]); getch(); } //function for translation void translation(int side[][3],int n) { int tx,ty,res[100][100]; printf("Enter the translation co-ordinates:"); scanf("%d%d",&tx,&ty); int mat[3][3]={{1,0,0},{0,1,0},{tx,ty,1}}; detectgraph(&gd,&gm); initgraph(&gd,&gm,""); for(int i=0;i<n-1;i++) line(side[i][0],side[i][1],side[i+1][0],side[i+1][1]); line(side[n-1][0],side[n-1][1],side[0][0],side[0][1]); for(int i=0;i<n;i++) for(int j=0;j<3;j++) for(int k=0;k<3;k++) res[i][j]+=side[i][k]*mat[k][j]; for(int i=0;i<n-1;i++) line(res[i][0],res[i][1],res[i+1][0],res[i+1][1]); line(res[n-1][0],res[n-1][1],res[0][0],res[0][1]); getch(); }
//driver program
int main()
{ int n,ch; printf("Enter number of sides:"); scanf("%d",&n); int side[n][3]; for(int i=0;i<n;i++) scanf("%d%d%d",&side[i][0],&side[i][1],&side[i][2]); printf("1-Translation\n2-Rotation\n3-Scaling\nEnter your choice:"); scanf("%d",&ch); switch(ch) { case 1: translation(side,n); break; case 2: rotation(side,n); break; case 3: scaling(side,n); break; default: printf("Wrong choice!!"); break; } return 0;
}

Tuesday, 30 April 2019

How to take backup of all your BlogSpot posts

- 2 comments

Blogger is the second most popular free blogging platform after WordPress. Blogger is own by Google and it has all the rights. Blogger is easy to set up compared to WordPress as it has fewer features and simple navigation. Most of the people who do full-time blogging prefer WordPress. 

Suppose you have started your blog in Blogger and now you want to shift to WordPress for some reasons and also want to move all your Blogger content to your new WordPress Website then I have got good news for you.

For all the bloggers who are thinking to move from blogger to WordPress, the main concern is how they can reuse the existing content of their website? or how to take the backup of all the blogger content?

I will explain here the step wise step process to take the backup of all your blogger posts. It's a simple three step process.






To backup blogger Content - 

  • Log in to your Blogger Dashboard
  • go to settings > other page 
  • Under import & Backup section click on the Backup content
How to take backup Blogger posts


  •  It will open up a popup saying Save To Computer 
how-to-backup-save-blogger-blog


  • Click on that save to computer button.
  • Save that .xml file in your computer which contains all the content you have ever posted in your blogger blog.


Sunday, 4 November 2018

Top 7 must have WordPress plugins for any WordPress website

- 26 comments
In this article, we will talk about the top 7 must have WordPress plugins for any WordPress website. You should try all these WordPress plugins as they will really benefit your business, grow your audience and drive more traffic to your website.

Follow along with me step by step as I will take you through each WordPress plugin explaining how each of them works and what benefits you will start to see.

You can easily use all the plugins as each plugin is absolutely free.



1: SEO Friendly Images 
This little WordPress plugin basically improves traffic from search engine. which is exactly what we want. SEO friendly images plugin automatically updates ALT and Title attribute of all your images for SEO purpose.

The ALT attribute is an important part of SEO as it describes your images to search engines. So, when we search any image this is a key determining factor for a match. The title also plays an important role as it provides information about the image when we hover the mouse above image. 

This is a simple WordPress plugin but extremely effective in getting your images to show up in search results and driving even more traffic to your website.


2: WP Socializer
It is a supercool WordPress plugin which inserts social bookmarking, sharing buttons as well as floating widgets. You can insert these buttons on the posts & sidebars so the people visiting your website can easily like and share your content on social media. There are a lot of social bookmarking plugins available which can be used in many possible ways.


3: Contact form 7
This Wordpress plugin enables you to add a contact form on your website & this is super easy to use. All you need to do is install and edit either existing contact form or create a new one from scratch. 
For any business, it is more important to have ways to generate leads. You can add contact form as a lead magnet. Having a lead magnet is incredibly important for the success of any business.


4: Yoast SEO WordPress Plugin
This is a complete WordPress SEO plugin that exists today. It incorporates everything from google snippet preview and page analysis functionality, which helps optimize your page content, image, title, meta description and a lot more.

There are also a lot of optimizations methods available in between. Yoast SEO also let you set templates for titles and meta description. So, you can come up with a template and don't have to think about these things. 

Snippet preview let you see how it will look like in google search.


5: Sumo me
 This is list builder WordPress Plugin and list builder converts a one-time visitor to lifelong readers. It is like exit intent in your website as whenever user will leave it will pop up immediately asking for visitors email address. 

It is completely customizable and free. This can be a game changer for your business if used properly.


6: Google XML Sitemaps
This WordPress plugin might look confusing. This plugin generates XML sitemaps which means it helps search engines like google to index your website much better and for the information in your website to retrieve more efficiently. Which results in much more traffic and high ranking in search results. Who doesn't want that and well this plugin does exactly the same.


7: Yoast Google Analytics:
This WordPress plugin starts tracking your visitors, who are they, where are they from, what are they doing on your website and what are they actually using to visit your website. Having this WordPress plugin allows you to know your audience because no two people think exactly the same. Having google analytics WordPress plugin helps you analyze visitor traffic and paint a complete picture of your audience. You can see what people are visiting your site up to. 

You can see the visual analysis of visitors for your pages like what they are visiting and what they like and then tailor your marketing strategies. Knowing all this helps you serve your current customer better as well as the new customer. 

Tuesday, 10 July 2018

learn sending emails in python

- No comments
If you are a working professional and your job is to send a lot of emails to the client or customers on daily basis. Then this will be a very hectic task for you as compose mail for each person in the list.

Python includes several modules in the standard library for working with emails and email servers. As a learning exercise, I recently worked with Python 3 to see how I could use python for sending emails using smtp servers. Here I am writing a tutorial for the same.



Before starting there are few prerequisites you must have -
  •  You must have python installed in your system.

  • Working Internet

Python has various libraries to work with emails. We will use smtplib.

smtplib:
SMTP stands for Simple Mail Transfer Protocol.
smtplib module defines an SMTP client session object and we will use this object to send emails in python to any internet machine with SMTP or ESMTP listener.

Sending emails in python is done using smtplib module using SMTP server.

Actual usage varies depending upon the complexity of email as for detailed emails we also need to use email module. The tutorial given below is for sending emails in python through Gmail.


Basic Script to send emails in Python:

First of all, you need to create an SMTP object and each object you create will be used for connection with one server

import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)

Next, we need to login to the server - 

server.login("youremailusername", "password")

And now send the email - 

msg = "\nHello!" # The /n separates the message from the headers (which we ignore for this example)
server.sendmail("you@gmail.com", "target@example.com", msg)


The script written above is very basic without header, subject etc. We will use email module to make it more advanced.


email module overview:
Python's email package contains many classes and functions for composing and parsing email messages. We will cover only a small section that is used to send emails.

Use of email package:
We can directly import email module but if we do this we need to write full module name. So we only import classes that are needed.

from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

After importing the required classes we will compose some of the basic headers.

fromaddr = "you@gmail.com"
toaddr = "target@example.com"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Python email"

now we will attach the body of the message to MIME(multipurpose internal mail extension) message.

body = "sending test emails using python"
msg.attach(MIMEText(body, 'plain'))

for sending the email we need to convert the message to string and then use the same procedure as above to send email using the SMTP server.

import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("youremailusername", "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)

Writing a function to send emails using Gmail in Python:
We will write a function which can return a dictionary of any addresses it could not forward to and other connetion problems raise errors.

import smtplib
 
def sendemail(from_addr, to_addr_list, cc_addr_list,
              subject, message,
              login, password,
              smtpserver='smtp.gmail.com:587'):
    header  = 'From: %s\n' % from_addr
    header += 'To: %s\n' % ','.join(to_addr_list)
    header += 'Cc: %s\n' % ','.join(cc_addr_list)
    header += 'Subject: %s\n\n' % subject
    message = header + message
 
    server = smtplib.SMTP(smtpserver)
    server.starttls()
    server.login(login,password)
    problems = server.sendmail(from_addr, to_addr_list, message)
    server.quit()
    return problems

Call the above function to send emails:

sendemail(from_addr    = 'python@RC.net', 
          to_addr_list = ['RC@gmail.com'],
          cc_addr_list = ['RC@xx.co.uk'], 
          subject      = 'Howdy', 
          message      = 'Howdy from a python function', 
          login        = 'pythonuser', 
          password     = 'XXXXX')